mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
add login/signup action
This commit is contained in:
5
browser/main/Actions/login.js
Normal file
5
browser/main/Actions/login.js
Normal file
@@ -0,0 +1,5 @@
|
||||
var Reflux = require('reflux')
|
||||
|
||||
var login = Reflux.createAction()
|
||||
|
||||
module.exports = login
|
||||
5
browser/main/Actions/register.js
Normal file
5
browser/main/Actions/register.js
Normal file
@@ -0,0 +1,5 @@
|
||||
var Reflux = require('reflux')
|
||||
|
||||
var register = Reflux.createAction()
|
||||
|
||||
module.exports = register
|
||||
6
browser/main/Actions/snippetUpdate.js
Normal file
6
browser/main/Actions/snippetUpdate.js
Normal file
@@ -0,0 +1,6 @@
|
||||
var Reflux = require('reflux')
|
||||
|
||||
// Creating an Action
|
||||
var snippetUpdate = Reflux.createAction()
|
||||
|
||||
module.exports = snippetUpdate
|
||||
@@ -10,8 +10,8 @@ var CodeEditor = React.createClass({
|
||||
componentDidMount: function () {
|
||||
var el = React.findDOMNode(this.refs.target)
|
||||
var editor = ace.edit(el)
|
||||
editor.setValue(this.props.code)
|
||||
editor.$blockScrolling = Infinity
|
||||
editor.setValue(this.props.code)
|
||||
editor.renderer.setShowGutter(true)
|
||||
editor.setTheme('ace/theme/xcode')
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ var CodeViewer = React.createClass({
|
||||
componentDidMount: function () {
|
||||
var el = React.findDOMNode(this.refs.target)
|
||||
var editor = ace.edit(el)
|
||||
editor.setValue(this.props.code)
|
||||
editor.$blockScrolling = Infinity
|
||||
editor.setValue(this.props.code)
|
||||
editor.renderer.setShowGutter(false)
|
||||
editor.setReadOnly(true)
|
||||
editor.setTheme('ace/theme/xcode')
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
var React = require('react/addons')
|
||||
var ReactRouter = require('react-router')
|
||||
var Link = ReactRouter.Link
|
||||
var Auth = require('../Services/Auth')
|
||||
|
||||
var AuthStore = require('../Stores/AuthStore')
|
||||
var login = require('../Actions/login')
|
||||
|
||||
module.exports = React.createClass({
|
||||
mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation],
|
||||
@@ -11,31 +13,54 @@ module.exports = React.createClass({
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
componentDidMount: function () {
|
||||
this.unsubscribe = AuthStore.listen(this.onLogin)
|
||||
},
|
||||
componentWillUnmount: function () {
|
||||
this.unsubscribe()
|
||||
},
|
||||
handleSubmit: function (e) {
|
||||
console.log(this.state)
|
||||
Auth.attempt()
|
||||
// TODO: request user data
|
||||
.then(function (user) {
|
||||
this.transitionTo('dashboard', {userName: user.name, planetName: user.name})
|
||||
}.bind(this))
|
||||
login({
|
||||
email: this.state.email,
|
||||
password: this.state.password
|
||||
})
|
||||
e.preventDefault()
|
||||
},
|
||||
onLogin: function (user) {
|
||||
var planet = user.Planets.length > 0 ? user.Planets[0] : null
|
||||
if (planet == null) {
|
||||
this.transitionTo('user', {userName: user.name})
|
||||
return
|
||||
}
|
||||
this.transitionTo('dashboard', {userName: user.name, planetName: planet.name})
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<div className='LoginContainer'>
|
||||
<h1 className='text-center'>CodeXen</h1>
|
||||
<h2 className='text-center'>Log In | <small><Link to='register'>Register</Link></small></h2>
|
||||
<img className='logo' src='resources/favicon-230x230.png'/>
|
||||
|
||||
<nav className='authNavigator text-center'><Link to='login'>Log In</Link> / <Link to='register'>Sign Up</Link></nav>
|
||||
|
||||
<div className='socialControl'>
|
||||
<p>Connect with</p>
|
||||
<button className='facebookBtn'><i className='fa fa-facebook fa-fw'/></button>
|
||||
<button className='githubBtn'><i className='fa fa-github fa-fw'/></button>
|
||||
</div>
|
||||
|
||||
<div className='divider'>
|
||||
<hr/>
|
||||
<div className='dividerLabel'>or</div>
|
||||
</div>
|
||||
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
<div className='form-group'>
|
||||
<label>E-mail</label>
|
||||
<input className='block-input' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
||||
<input className='stripInput' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
||||
</div>
|
||||
<div className='form-group'>
|
||||
<label>Password</label>
|
||||
<input className='block-input' valueLink={this.linkState('password')} onChange={this.handleChange} type='password' placeholder='Password'/>
|
||||
<input className='stripInput' valueLink={this.linkState('password')} onChange={this.handleChange} type='password' placeholder='Password'/>
|
||||
</div>
|
||||
<div className='form-group'>
|
||||
<button className='btn-primary btn-block' type='submit'><i className='fa fa-sign-in'></i> Login</button>
|
||||
<button className='btn-primary' type='submit'><i className='fa fa-sign-in'></i> Log In</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,7 @@ var currentUser = {
|
||||
var userPlanets = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'testcat',
|
||||
name: 'myplanet',
|
||||
profileName: 'TestCat'
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
var React = require('react/addons')
|
||||
var ReactRouter = require('react-router')
|
||||
var Link = ReactRouter.Link
|
||||
var Auth = require('../Services/Auth')
|
||||
|
||||
var AuthStore = require('../Stores/AuthStore')
|
||||
var register = require('../Actions/register')
|
||||
|
||||
module.exports = React.createClass({
|
||||
mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation],
|
||||
@@ -13,42 +15,67 @@ module.exports = React.createClass({
|
||||
profileName: ''
|
||||
}
|
||||
},
|
||||
componentDidMount: function () {
|
||||
this.unsubscribe = AuthStore.listen(this.onRegister)
|
||||
},
|
||||
componentWillUnmount: function () {
|
||||
this.unsubscribe()
|
||||
},
|
||||
handleSubmit: function (e) {
|
||||
Auth.register()
|
||||
// TODO: request user data
|
||||
.then(function (user) {
|
||||
this.transitionTo('dashboard', {userName: user.name, planetName: user.name})
|
||||
}.bind(this))
|
||||
register({
|
||||
email: this.state.email,
|
||||
password: this.state.password,
|
||||
name: this.state.name,
|
||||
profileName: this.state.profileName
|
||||
})
|
||||
|
||||
e.preventDefault()
|
||||
},
|
||||
onRegister: function (user) {
|
||||
var planet = user.Planets.length > 0 ? user.Planets[0] : null
|
||||
if (planet == null) {
|
||||
this.transitionTo('user', {userName: user.name})
|
||||
return
|
||||
}
|
||||
this.transitionTo('dashboard', {userName: user.name, planetName: planet.name})
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
<div className='RegisterContainer'>
|
||||
<h1 className='text-center'>CodeXen</h1>
|
||||
<h2 className='text-center'><small><Link to='login'>Log In</Link></small> | Register</h2>
|
||||
<img className='logo' src='resources/favicon-230x230.png'/>
|
||||
|
||||
<nav className='authNavigator text-center'><Link to='login'>Log In</Link> / <Link to='register'>Sign Up</Link></nav>
|
||||
|
||||
<div className='socialControl'>
|
||||
<p>Connect with</p>
|
||||
<button className='facebookBtn'><i className='fa fa-facebook fa-fw'/></button>
|
||||
<button className='githubBtn'><i className='fa fa-github fa-fw'/></button>
|
||||
</div>
|
||||
|
||||
<div className='divider'>
|
||||
<hr/>
|
||||
<div className='dividerLabel'>or</div>
|
||||
</div>
|
||||
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
<div className='form-group'>
|
||||
<label>E-mail</label>
|
||||
<input className='block-input' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
||||
<input className='stripInput' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
||||
</div>
|
||||
<div className='form-group'>
|
||||
<label>Password</label>
|
||||
<input className='block-input' valueLink={this.linkState('password')} type='password' placeholder='Password'/>
|
||||
</div>
|
||||
<hr></hr>
|
||||
<div className='form-group'>
|
||||
<label>User name</label>
|
||||
<input className='block-input' valueLink={this.linkState('name')} type='text' placeholder='name'/>
|
||||
<input className='stripInput' valueLink={this.linkState('password')} type='password' placeholder='Password'/>
|
||||
</div>
|
||||
<div className='form-group'>
|
||||
<label>Profile name</label>
|
||||
<input className='block-input' valueLink={this.linkState('profileName')} type='text' placeholder='Profile name'/>
|
||||
<input className='stripInput' valueLink={this.linkState('name')} type='text' placeholder='name'/>
|
||||
</div>
|
||||
<div className='form-group'>
|
||||
<button className='btn-primary btn-block' type='submit'><i className='fa fa-sign-in'></i> Register</button>
|
||||
<input className='stripInput' valueLink={this.linkState('profileName')} type='text' placeholder='Profile name'/>
|
||||
</div>
|
||||
<div className='form-group'>
|
||||
<button className='btn-primary' type='submit'><i className='fa fa-sign-in'></i> Sign Up</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p>Sign Upをクリックすることで、当サイトの利用規約及びCookieの使用を含むデータに関するポリシーに同意するものとします。</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var Snippet = {}
|
||||
|
||||
var snippets = {
|
||||
testcat: [
|
||||
myplanet: [
|
||||
{
|
||||
id: 1,
|
||||
callSign: 'alert',
|
||||
|
||||
39
browser/main/Stores/AuthStore.js
Normal file
39
browser/main/Stores/AuthStore.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/* global localStorage */
|
||||
var Reflux = require('reflux')
|
||||
var request = require('superagent')
|
||||
|
||||
var login = require('../Actions/login')
|
||||
var register = require('../Actions/register')
|
||||
|
||||
var AuthStore = Reflux.createStore({
|
||||
init: function () {
|
||||
this.listenTo(login, this.login)
|
||||
this.listenTo(register, this.register)
|
||||
},
|
||||
login: function (input) {
|
||||
request
|
||||
.post('http://localhost:8000/auth/login')
|
||||
.send(input)
|
||||
.set('Accept', 'application/json')
|
||||
.end(function (err, res) {
|
||||
if (err) console.error(err)
|
||||
var user = res.body.user
|
||||
localStorage.setItem('token', res.body.token)
|
||||
this.trigger(user)
|
||||
}.bind(this))
|
||||
},
|
||||
register: function (input) {
|
||||
request
|
||||
.post('http://localhost:8000/auth/signup')
|
||||
.send(input)
|
||||
.set('Accept', 'application/json')
|
||||
.end(function (err, res) {
|
||||
if (err) console.error(err)
|
||||
var user = res.body.user
|
||||
localStorage.setItem('token', res.body.token)
|
||||
this.trigger(user)
|
||||
}.bind(this))
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = AuthStore
|
||||
BIN
browser/main/favicon.ico
Normal file
BIN
browser/main/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -4,6 +4,7 @@
|
||||
<title>CodeXen</title>
|
||||
|
||||
<link rel="stylesheet" href="../vendor/fontawesome/css/font-awesome.min.css" media="screen" title="no title" charset="utf-8">
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
|
||||
<script src="../vendor/react/react-with-addons.js"></script>
|
||||
<script src="../vendor/react-router/build/umd/ReactRouter.js"></script>
|
||||
|
||||
BIN
browser/main/resources/favicon-230x230.png
Normal file
BIN
browser/main/resources/favicon-230x230.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
Reference in New Issue
Block a user