-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from RobertoLewis/dev
[add] username appears in header on successful login or registration
- Loading branch information
Showing
8 changed files
with
142 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 86 additions & 8 deletions
94
applications/kcp-main/shared/components/Profile/registration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,107 @@ | ||
import React, {PropTypes, Component} from 'react'; | ||
import { reduxForm } from 'redux-form'; | ||
import * as actions from '../../redux/actions'; | ||
|
||
export default class Registration extends Component { | ||
class Registration extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
} | ||
|
||
handleFormSubmit(formProps) { | ||
// console.log("registration info: ", formProps); | ||
// Call action creator to sign up the user | ||
this.props.registerUser(formProps); | ||
|
||
} | ||
|
||
renderAlert() { | ||
if (this.props.errorMessage) { | ||
return ( | ||
<div className="alert alert-danger"> | ||
<strong>Error</strong> {this.props.errorMessage} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
render() { | ||
const { handleSubmit, fields: { username, email, password, passwordConfirm }} = this.props; | ||
|
||
return ( | ||
<div className="registration-page"> | ||
<div className="form"> | ||
<form className="registration-form"> | ||
<input type="text" placeholder="username"/> | ||
<input type="text" placeholder="email"/> | ||
<input type="text" placeholder="password"/> | ||
<input type="text" placeholder="confirm password"/> | ||
<button className="btn btn-default btn-lg" >register</button> | ||
<form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))} className="registration-form"> | ||
<fieldset className="form-group" > | ||
<label>username</label> | ||
<input className="form-control" placeholder="username"{...username}/> | ||
{username.touched && username.error && <div className="error">{username.error}</div>} | ||
</fieldset> | ||
<fieldset className="form-group"> | ||
<label>email</label> | ||
<input className="form-control" placeholder="[email protected]" {...email}/> | ||
{email.touched && email.error && <div className='error'>{email.error}</div>} | ||
</fieldset> | ||
<fieldset className="form-group"> | ||
<label>password</label> | ||
<input className="form-control" type="password" placeholder="password" {...password}/> | ||
{password.touched && password.error && <div className="error">{password.error}</div>} | ||
</fieldset> | ||
<fieldset className="form-group"> | ||
<label>confirm password</label> | ||
<input className="form-control" type="password" placeholder="password" {...passwordConfirm}/> | ||
{passwordConfirm.touched && passwordConfirm.error && <div className='error'>{passwordConfirm.error}</div>} | ||
</fieldset> | ||
{this.renderAlert()} | ||
|
||
<button action="submit" className="btn btn-default btn-lg" >register</button> | ||
|
||
</form> | ||
</div> | ||
|
||
|
||
</div> | ||
|
||
); | ||
} | ||
|
||
} | ||
|
||
function validate(formProps) { | ||
const errors = {}; | ||
|
||
if (!formProps.username) { | ||
errors.username = 'Please enter a username'; | ||
} | ||
|
||
if (!formProps.email) { | ||
errors.email = 'Please enter an email'; | ||
} | ||
|
||
if (!formProps.password) { | ||
errors.password = 'Please enter a password'; | ||
} | ||
|
||
if (!formProps.passwordConfirm) { | ||
errors.passwordConfirm = 'Please enter a password confirmation'; | ||
} | ||
|
||
//ensures that passwords match | ||
if (formProps.password !== formProps.passwordConfirm) { | ||
errors.password = 'Passwords must match'; | ||
} | ||
|
||
console.log("formProps: ", formProps); | ||
|
||
return errors; | ||
} | ||
|
||
function mapStateToProps(state) { | ||
return { errorMessage: state.auth.error }; | ||
|
||
} | ||
|
||
export default reduxForm({ | ||
form: 'registration', | ||
fields: ['username', 'email', 'password', 'passwordConfirm'], | ||
validate | ||
}, mapStateToProps, actions)(Registration); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
/*begin form*/ | ||
|
||
.error { | ||
color: red; | ||
} | ||
|
||
.login-page { | ||
width: 360px; | ||
padding: 8% 0 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters