-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(authentication): reset password
- send a clickable link to email entered into a form - enter password details to change password
- Loading branch information
Showing
15 changed files
with
753 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import Loader from 'react-loader'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ForgotPasswordForm = ({ | ||
onChange, | ||
onSave, | ||
username, | ||
email, | ||
loading, | ||
}) => ( | ||
<div className="reset-container container"> | ||
<div className="panel-body"> | ||
<div className="text-center resetPasswordForm"> | ||
<h3><i className="fa fa-lock fa-4x" /></h3> | ||
<h2 className="text-center">Forgot Password?</h2> | ||
<p>Enter your username and email here to receive a reset link.</p> | ||
<div className="panel-body"> | ||
<div role="form" autoComplete="off" className="form"> | ||
<div className="form-group"> | ||
<div className="input-group"> | ||
<div className="input-group-prepend"> | ||
<div className="input-group-text"><i className="fas fa-user" /></div> | ||
</div> | ||
<input id="username" name="username" placeholder="username" value={username} className="form-control" type="text" onChange={onChange} /> | ||
</div> | ||
</div> | ||
<div className="form-group"> | ||
<div className="input-group"> | ||
<div className="input-group-prepend"> | ||
<div className="input-group-text"><i className="fas fa-envelope" /></div> | ||
</div> | ||
<input id="email" name="email" placeholder="email address" value={email} className="form-control" type="email" onChange={onChange} /> | ||
</div> | ||
</div> | ||
<Loader loaded={!loading}> | ||
<div className="form-group"> | ||
<input name="recover-submit" className="btn btn-lg btn-primary btn-block" value="Submit" type="submit" onClick={onSave} /> | ||
</div> | ||
</Loader> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
ForgotPasswordForm.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
onSave: PropTypes.func.isRequired, | ||
username: PropTypes.string.isRequired, | ||
email: PropTypes.string.isRequired, | ||
loading: PropTypes.bool.isRequired, | ||
}; | ||
|
||
|
||
export default ForgotPasswordForm; |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import SendResetLinkForm from './ForgotPasswordForm'; | ||
import { sendResetLink } from '../../actions/userActions'; | ||
|
||
export class ForgotPassword extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
username: '', | ||
email: '', | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.sendLinkSuccess === true) { | ||
const { history } = this.props; | ||
history.push('/'); | ||
} | ||
} | ||
|
||
handleChange = event => { | ||
const { name, value } = event.target; | ||
this.setState({ [name]: value }); | ||
}; | ||
|
||
handleSubmit = event => { | ||
event.preventDefault(); | ||
const { email, username } = this.state; | ||
const payload = { | ||
user: { | ||
email, | ||
username, | ||
}, | ||
}; | ||
const { dispatch } = this.props; | ||
dispatch(sendResetLink(payload)); | ||
} | ||
|
||
render() { | ||
const { username, email } = this.state; | ||
const { resetPasswordloading } = this.props; | ||
return ( | ||
<SendResetLinkForm | ||
onChange={this.handleChange} | ||
onSave={this.handleSubmit} | ||
username={username} | ||
email={email} | ||
loading={resetPasswordloading} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export const mapStateToProps = state => ({ | ||
sendLinkSuccess: state.user.sendLinkSuccess, | ||
sendLinkError: state.user.sendLinkError, | ||
resetPasswordloading: state.user.resetPasswordloading, | ||
}); | ||
|
||
ForgotPassword.propTypes = { | ||
dispatch: PropTypes.func.isRequired, | ||
sendLinkSuccess: PropTypes.bool, | ||
resetPasswordloading: PropTypes.bool, | ||
history: PropTypes.object.isRequired, | ||
}; | ||
|
||
ForgotPassword.defaultProps = { | ||
sendLinkSuccess: false, | ||
resetPasswordloading: false, | ||
}; | ||
|
||
export default connect(mapStateToProps)(ForgotPassword); |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const ResetPasswordForm = ({ | ||
onChange, | ||
onSave, | ||
password1, | ||
password2, | ||
}) => ( | ||
<div className="container reset-container"> | ||
<div className="panel-body"> | ||
<div className="text-center resetPasswordForm"> | ||
<h3><i className="fa fa-lock-open fa-4x" /></h3> | ||
<h2 className="text-center">Reset Password</h2> | ||
<p>Change your password here and login again</p> | ||
<div className="panel-body"> | ||
<div role="form" autoComplete="off" className="form"> | ||
<div className="form-group"> | ||
<div className="input-group"> | ||
<div className="input-group-prepend"> | ||
<div className="input-group-text"><i className="fas fa-lock" /></div> | ||
</div> | ||
<input id="password1" name="password1" placeholder="password" value={password1} className="form-control" type="password" onChange={onChange} /> | ||
</div> | ||
</div> | ||
<div className="form-group"> | ||
<div className="input-group"> | ||
<div className="input-group-prepend"> | ||
<div className="input-group-text"><i className="fas fa-lock" /></div> | ||
</div> | ||
<input id="password2" name="password2" placeholder="confirm password" value={password2} className="form-control" type="password" onChange={onChange} /> | ||
</div> | ||
</div> | ||
<div className="form-group"> | ||
<input name="recover-submit" className="btn btn-lg btn-primary btn-block" value="Reset" type="submit" onClick={onSave} /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
ResetPasswordForm.propTypes = { | ||
onChange: PropTypes.func.isRequired, | ||
onSave: PropTypes.func.isRequired, | ||
password1: PropTypes.string.isRequired, | ||
password2: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default ResetPasswordForm; |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { toast } from 'react-toastify'; | ||
import PropTypes from 'prop-types'; | ||
import ResetPasswordForm from './ResetPasswordForm'; | ||
import { resetPassword } from '../../actions/userActions'; | ||
|
||
export class ResetPassword extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
password1: '', | ||
password2: '', | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const { match: { params: { token } } } = this.props; | ||
localStorage.setItem('auth_token', token); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.updatePasswordSuccess === true) { | ||
const { history } = this.props; | ||
history.push('/login'); | ||
} | ||
} | ||
|
||
handleChange = event => { | ||
const { name, value } = event.target; | ||
this.setState({ [name]: value }); | ||
}; | ||
|
||
handleSubmit = event => { | ||
event.preventDefault(); | ||
const { password2, password1 } = this.state; | ||
if (password2 === password1) { | ||
const payload = { | ||
user: { | ||
password: password2, | ||
}, | ||
}; | ||
const { dispatch } = this.props; | ||
return dispatch(resetPassword(payload)); | ||
} | ||
return toast.error('Make sure the password entered is the same', { autoClose: 3500, hideProgressBar: true }); | ||
}; | ||
|
||
|
||
render() { | ||
const formDetails = this.state; | ||
return ( | ||
<ResetPasswordForm | ||
onChange={this.handleChange} | ||
onSave={this.handleSubmit} | ||
password1={formDetails.password1} | ||
password2={formDetails.password2} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
updatePasswordSuccess: state.user.resetPasswordSuccess, | ||
updatePasswordError: state.user.resetPasswordError, | ||
}); | ||
|
||
|
||
ResetPassword.defaultProps = { | ||
updatePasswordSuccess: false, | ||
}; | ||
|
||
|
||
ResetPassword.propTypes = { | ||
dispatch: PropTypes.func.isRequired, | ||
match: PropTypes.object.isRequired, | ||
updatePasswordSuccess: PropTypes.bool, | ||
history: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default connect(mapStateToProps)(ResetPassword); |
Oops, something went wrong.