mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +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 () {
|
componentDidMount: function () {
|
||||||
var el = React.findDOMNode(this.refs.target)
|
var el = React.findDOMNode(this.refs.target)
|
||||||
var editor = ace.edit(el)
|
var editor = ace.edit(el)
|
||||||
editor.setValue(this.props.code)
|
|
||||||
editor.$blockScrolling = Infinity
|
editor.$blockScrolling = Infinity
|
||||||
|
editor.setValue(this.props.code)
|
||||||
editor.renderer.setShowGutter(true)
|
editor.renderer.setShowGutter(true)
|
||||||
editor.setTheme('ace/theme/xcode')
|
editor.setTheme('ace/theme/xcode')
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ var CodeViewer = React.createClass({
|
|||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
var el = React.findDOMNode(this.refs.target)
|
var el = React.findDOMNode(this.refs.target)
|
||||||
var editor = ace.edit(el)
|
var editor = ace.edit(el)
|
||||||
editor.setValue(this.props.code)
|
|
||||||
editor.$blockScrolling = Infinity
|
editor.$blockScrolling = Infinity
|
||||||
|
editor.setValue(this.props.code)
|
||||||
editor.renderer.setShowGutter(false)
|
editor.renderer.setShowGutter(false)
|
||||||
editor.setReadOnly(true)
|
editor.setReadOnly(true)
|
||||||
editor.setTheme('ace/theme/xcode')
|
editor.setTheme('ace/theme/xcode')
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
var React = require('react/addons')
|
var React = require('react/addons')
|
||||||
var ReactRouter = require('react-router')
|
var ReactRouter = require('react-router')
|
||||||
var Link = ReactRouter.Link
|
var Link = ReactRouter.Link
|
||||||
var Auth = require('../Services/Auth')
|
|
||||||
|
var AuthStore = require('../Stores/AuthStore')
|
||||||
|
var login = require('../Actions/login')
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation],
|
mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation],
|
||||||
@@ -11,31 +13,54 @@ module.exports = React.createClass({
|
|||||||
password: ''
|
password: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
this.unsubscribe = AuthStore.listen(this.onLogin)
|
||||||
|
},
|
||||||
|
componentWillUnmount: function () {
|
||||||
|
this.unsubscribe()
|
||||||
|
},
|
||||||
handleSubmit: function (e) {
|
handleSubmit: function (e) {
|
||||||
console.log(this.state)
|
login({
|
||||||
Auth.attempt()
|
email: this.state.email,
|
||||||
// TODO: request user data
|
password: this.state.password
|
||||||
.then(function (user) {
|
})
|
||||||
this.transitionTo('dashboard', {userName: user.name, planetName: user.name})
|
|
||||||
}.bind(this))
|
|
||||||
e.preventDefault()
|
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 () {
|
render: function () {
|
||||||
return (
|
return (
|
||||||
<div className='LoginContainer'>
|
<div className='LoginContainer'>
|
||||||
<h1 className='text-center'>CodeXen</h1>
|
<img className='logo' src='resources/favicon-230x230.png'/>
|
||||||
<h2 className='text-center'>Log In | <small><Link to='register'>Register</Link></small></h2>
|
|
||||||
|
<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}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<label>E-mail</label>
|
<input className='stripInput' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
||||||
<input className='block-input' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<label>Password</label>
|
<input className='stripInput' valueLink={this.linkState('password')} onChange={this.handleChange} type='password' placeholder='Password'/>
|
||||||
<input className='block-input' valueLink={this.linkState('password')} onChange={this.handleChange} type='password' placeholder='Password'/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className='form-group'>
|
<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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var currentUser = {
|
|||||||
var userPlanets = [
|
var userPlanets = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'testcat',
|
name: 'myplanet',
|
||||||
profileName: 'TestCat'
|
profileName: 'TestCat'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
var React = require('react/addons')
|
var React = require('react/addons')
|
||||||
var ReactRouter = require('react-router')
|
var ReactRouter = require('react-router')
|
||||||
var Link = ReactRouter.Link
|
var Link = ReactRouter.Link
|
||||||
var Auth = require('../Services/Auth')
|
|
||||||
|
var AuthStore = require('../Stores/AuthStore')
|
||||||
|
var register = require('../Actions/register')
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation],
|
mixins: [React.addons.LinkedStateMixin, ReactRouter.Navigation],
|
||||||
@@ -13,42 +15,67 @@ module.exports = React.createClass({
|
|||||||
profileName: ''
|
profileName: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
this.unsubscribe = AuthStore.listen(this.onRegister)
|
||||||
|
},
|
||||||
|
componentWillUnmount: function () {
|
||||||
|
this.unsubscribe()
|
||||||
|
},
|
||||||
handleSubmit: function (e) {
|
handleSubmit: function (e) {
|
||||||
Auth.register()
|
register({
|
||||||
// TODO: request user data
|
email: this.state.email,
|
||||||
.then(function (user) {
|
password: this.state.password,
|
||||||
this.transitionTo('dashboard', {userName: user.name, planetName: user.name})
|
name: this.state.name,
|
||||||
}.bind(this))
|
profileName: this.state.profileName
|
||||||
|
})
|
||||||
|
|
||||||
e.preventDefault()
|
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 () {
|
render: function () {
|
||||||
return (
|
return (
|
||||||
<div className='RegisterContainer'>
|
<div className='RegisterContainer'>
|
||||||
<h1 className='text-center'>CodeXen</h1>
|
<img className='logo' src='resources/favicon-230x230.png'/>
|
||||||
<h2 className='text-center'><small><Link to='login'>Log In</Link></small> | Register</h2>
|
|
||||||
|
<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}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<label>E-mail</label>
|
<input className='stripInput' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
||||||
<input className='block-input' valueLink={this.linkState('email')} type='text' placeholder='E-mail'/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<label>Password</label>
|
<input className='stripInput' valueLink={this.linkState('password')} type='password' placeholder='Password'/>
|
||||||
<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'/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<label>Profile name</label>
|
<input className='stripInput' valueLink={this.linkState('name')} type='text' placeholder='name'/>
|
||||||
<input className='block-input' valueLink={this.linkState('profileName')} type='text' placeholder='Profile name'/>
|
|
||||||
</div>
|
</div>
|
||||||
<div className='form-group'>
|
<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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<p>Sign Upをクリックすることで、当サイトの利用規約及びCookieの使用を含むデータに関するポリシーに同意するものとします。</p>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
var Snippet = {}
|
var Snippet = {}
|
||||||
|
|
||||||
var snippets = {
|
var snippets = {
|
||||||
testcat: [
|
myplanet: [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
callSign: 'alert',
|
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>
|
<title>CodeXen</title>
|
||||||
|
|
||||||
<link rel="stylesheet" href="../vendor/fontawesome/css/font-awesome.min.css" media="screen" title="no title" charset="utf-8">
|
<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/react-with-addons.js"></script>
|
||||||
<script src="../vendor/react-router/build/umd/ReactRouter.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 |
55
browser/styles/main/containers/LoginContainer.styl
Normal file
55
browser/styles/main/containers/LoginContainer.styl
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
.LoginContainer, .RegisterContainer
|
||||||
|
margin 15px auto
|
||||||
|
padding 25px 15px
|
||||||
|
box-sizing border-box
|
||||||
|
color inactiveTextColor
|
||||||
|
.logo
|
||||||
|
display block
|
||||||
|
margin 0 auto
|
||||||
|
.authNavigator
|
||||||
|
margin 15px 0
|
||||||
|
a
|
||||||
|
font-size 1.5em
|
||||||
|
text-decoration none
|
||||||
|
color inactiveTextColor
|
||||||
|
&:hover, &.hover, &:active, &.active
|
||||||
|
color brandColor
|
||||||
|
.socialControl
|
||||||
|
text-align center
|
||||||
|
margin 25px 0
|
||||||
|
p
|
||||||
|
margin-bottom 25px
|
||||||
|
.facebookBtn, .githubBtn
|
||||||
|
padding 20px
|
||||||
|
margin 0 45px
|
||||||
|
background-image none
|
||||||
|
font-size 25px
|
||||||
|
color white
|
||||||
|
border none
|
||||||
|
circle()
|
||||||
|
cursor pointer
|
||||||
|
.facebookBtn
|
||||||
|
background-color facebookColor
|
||||||
|
&:hover, &.hover
|
||||||
|
background-color lighten(facebookColor, 25%)
|
||||||
|
.githubBtn
|
||||||
|
background-color githubBtn
|
||||||
|
&:hover, &.hover
|
||||||
|
background-color lighten(githubBtn, 25%)
|
||||||
|
.divider
|
||||||
|
.dividerLabel
|
||||||
|
text-align center
|
||||||
|
position relative
|
||||||
|
top -35px
|
||||||
|
background-color backgroundColor
|
||||||
|
margin 0 auto
|
||||||
|
width 50px
|
||||||
|
form
|
||||||
|
width 400px
|
||||||
|
margin 0 auto 45px
|
||||||
|
div.form-group:last-child
|
||||||
|
margin-top 45px
|
||||||
|
.btn-primary
|
||||||
|
display block
|
||||||
|
width 200px
|
||||||
|
margin 0 auto
|
||||||
@@ -38,11 +38,23 @@ button
|
|||||||
text-align center
|
text-align center
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
margin-bottom 15px
|
margin-bottom 20px
|
||||||
&>label
|
&>label
|
||||||
display block
|
display block
|
||||||
margin-bottom 5px
|
margin-bottom 5px
|
||||||
|
|
||||||
|
.stripInput
|
||||||
|
border none
|
||||||
|
border-bottom 1px solid borderColor
|
||||||
|
padding 5px 15px
|
||||||
|
width 100%
|
||||||
|
display block
|
||||||
|
font-size 1em
|
||||||
|
height 33px
|
||||||
|
box-sizing border-box
|
||||||
|
&:focus, &.focus
|
||||||
|
border-bottom 1px solid brandBorderColor
|
||||||
|
outline none
|
||||||
|
|
||||||
.block-input, .inline-input
|
.block-input, .inline-input
|
||||||
border solid 1px borderColor
|
border solid 1px borderColor
|
||||||
@@ -74,14 +86,6 @@ textarea.block-input
|
|||||||
#content
|
#content
|
||||||
fullsize()
|
fullsize()
|
||||||
|
|
||||||
.LoginContainer, .RegisterContainer
|
|
||||||
width 400px
|
|
||||||
margin 15px auto
|
|
||||||
padding 25px 15px
|
|
||||||
box-sizing border-box
|
|
||||||
h1, h2
|
|
||||||
margin 5px auto 25px
|
|
||||||
|
|
||||||
.UserNavigator
|
.UserNavigator
|
||||||
background-color planetNavBgColor
|
background-color planetNavBgColor
|
||||||
absolute left top bottom
|
absolute left top bottom
|
||||||
|
|||||||
@@ -39,5 +39,5 @@
|
|||||||
|
|
||||||
.ace_editor
|
.ace_editor
|
||||||
height 300px
|
height 300px
|
||||||
border-radius 5px
|
border-radius 10px
|
||||||
border solid 1px borderColor
|
border solid 1px borderColor
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ hoverBackgroundColor= transparentify(#444, 3%)
|
|||||||
|
|
||||||
|
|
||||||
// v0.2.0
|
// v0.2.0
|
||||||
|
inactiveTextColor = #888
|
||||||
textColor = #4D4D4D
|
textColor = #4D4D4D
|
||||||
backgroundColor= white
|
backgroundColor= white
|
||||||
|
|
||||||
@@ -27,3 +28,6 @@ planetAnchorActiveBgColor = white
|
|||||||
|
|
||||||
popupShadow = 0 0 5px 0 #888
|
popupShadow = 0 0 5px 0 #888
|
||||||
modalBaseColor = transparentify(white, 65%)
|
modalBaseColor = transparentify(white, 65%)
|
||||||
|
|
||||||
|
facebookColor= #3b5998
|
||||||
|
githubBtn= #201F1F
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
"homepage": "https://github.com/Rokt33r/codexen-app#readme",
|
"homepage": "https://github.com/Rokt33r/codexen-app#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^1.1.0",
|
"dotenv": "^1.1.0",
|
||||||
|
"halogen": "^0.1.10",
|
||||||
"marked": "^0.3.3",
|
"marked": "^0.3.3",
|
||||||
"moment": "^2.10.3",
|
"moment": "^2.10.3",
|
||||||
"node-jsx": "^0.13.3",
|
"node-jsx": "^0.13.3",
|
||||||
@@ -39,7 +40,8 @@
|
|||||||
"react-router": "^0.13.3",
|
"react-router": "^0.13.3",
|
||||||
"react-select": "^0.5.4",
|
"react-select": "^0.5.4",
|
||||||
"react-tooltip": "^0.3.3",
|
"react-tooltip": "^0.3.3",
|
||||||
"reflux": "^0.2.8"
|
"reflux": "^0.2.8",
|
||||||
|
"superagent": "^1.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"css-loader": "^0.15.1",
|
"css-loader": "^0.15.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user