store signup in redux

This commit is contained in:
catarak 2016-06-14 14:46:40 -04:00
parent a79391c96c
commit 0c54f372c1
8 changed files with 24 additions and 12 deletions

View file

@ -24,7 +24,10 @@ export function createUser(req, res, next) {
if (err) { if (err) {
return next(err); return next(err);
} }
res.json({success: true}); res.json({
email: req.user.email,
username: req.user.username
});
}); });
}); });
}); });

View file

@ -7,7 +7,8 @@ class Nav extends React.Component {
<nav className="nav"> <nav className="nav">
<ul className="nav__items"> <ul className="nav__items">
<li> <li>
<Link to={`/login`}>Login</Link> or <Link to={`/signup`}>Sign Up</Link> {this.props.user.authenticated && <p>Hello, {this.props.user.username}!</p>}
{!this.props.user.authenticated && <p><Link to={`/login`}>Login</Link> or <Link to={`/signup`}>Sign Up</Link></p>}
</li> </li>
</ul> </ul>
</nav> </nav>

View file

@ -5,19 +5,19 @@ class SignupForm extends React.Component {
const {fields: { username, email, password, confirmPassword }, handleSubmit} = this.props; const {fields: { username, email, password, confirmPassword }, handleSubmit} = this.props;
return ( return (
<form className="signup-form" onSubmit={handleSubmit(this.props.signUpUser.bind(this))}> <form className="signup-form" onSubmit={handleSubmit(this.props.signUpUser.bind(this))}>
<p> <p className="signup-form__field">
<label className="signup-form__username-label" for="username">Username:</label> <label className="signup-form__username-label" for="username">Username:</label>
<input className="signup-form__username-input" id="username" type="text" placeholder="Username" {...username}/> <input className="signup-form__username-input" id="username" type="text" placeholder="Username" {...username}/>
</p> </p>
<p> <p className="signup-form__field">
<label className="signup-form__email-label" for="email">Email:</label> <label className="signup-form__email-label" for="email">Email:</label>
<input className="signup-form__email-input" id="email" type="text" placeholder="Email" {...email}/> <input className="signup-form__email-input" id="email" type="text" placeholder="Email" {...email}/>
</p> </p>
<p> <p className="signup-form__field">
<label className="signup-form__password-label" for="password">Password:</label> <label className="signup-form__password-label" for="password">Password:</label>
<input className="signup-form__password-input" id="password" type="password" placeholder="Password" {...password}/> <input className="signup-form__password-input" id="password" type="password" placeholder="Password" {...password}/>
</p> </p>
<p> <p className="signup-form__field">
<label className="signup-form__confirm-password-label" for="confirm-password">Confirm Password:</label> <label className="signup-form__confirm-password-label" for="confirm-password">Confirm Password:</label>
<input className="signup-form__confirm-password-input" id="confirm-password" type="password" placeholder="Confirm Password" {...confirmPassword}/> <input className="signup-form__confirm-password-input" id="confirm-password" type="password" placeholder="Confirm Password" {...confirmPassword}/>
</p> </p>

View file

@ -12,7 +12,7 @@ class IDEView extends React.Component {
render() { render() {
return ( return (
<div className="ide"> <div className="ide">
<Nav /> <Nav user={this.props.user}/>
<Toolbar <Toolbar
className="Toolbar" className="Toolbar"
isPlaying={this.props.ide.isPlaying} isPlaying={this.props.ide.isPlaying}
@ -46,7 +46,8 @@ function mapStateToProps(state) {
return { return {
file: state.file, file: state.file,
ide: state.ide, ide: state.ide,
preferences: state.preferences preferences: state.preferences,
user: state.user
} }
} }

View file

@ -9,7 +9,9 @@ export function signUpUser(formValues) {
return function(dispatch) { return function(dispatch) {
axios.post(`${ROOT_URL}/signup`, formValues, {withCredentials: true}) axios.post(`${ROOT_URL}/signup`, formValues, {withCredentials: true})
.then(response => { .then(response => {
dispatch({ type: ActionTypes.AUTH_USER }); dispatch({ type: ActionTypes.AUTH_USER,
user: response.data
});
browserHistory.push('/'); browserHistory.push('/');
}) })
.catch(response => dispatch(authError(response.data.error))); .catch(response => dispatch(authError(response.data.error)));

View file

@ -1,9 +1,10 @@
import * as ActionTypes from '../constants/constants' import * as ActionTypes from '../constants/constants'
const user = (state = {}, action) => { const user = (state = {authenticated: false}, action) => {
switch (action.type) { switch (action.type) {
case ActionTypes.AUTH_USER: case ActionTypes.AUTH_USER:
return { ...state, error: '', authenticated: true }; return { ...action.user,
authenticated: true };
default: default:
return state; return state;
} }

View file

@ -7,7 +7,7 @@ html, body {
height: 100%; height: 100%;
} }
ul { ul, p {
padding: 0; padding: 0;
margin: 0; margin: 0;
} }

View file

@ -18,4 +18,8 @@
.signup-form__password-input, .signup-form__password-input,
.signup-form__confirm-password-input { .signup-form__confirm-password-input {
width: #{300 / $base-font-size}rem; width: #{300 / $base-font-size}rem;
}
.signup-form__field {
margin: #{20 / $base-font-size}rem 0;
} }