2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-12-19 21:49:37 +00:00
|
|
|
import { reduxForm } from 'redux-form';
|
|
|
|
import classNames from 'classnames';
|
2017-02-22 19:29:35 +00:00
|
|
|
import { bindActionCreators } from 'redux';
|
2018-02-23 16:31:41 +00:00
|
|
|
import { Helmet } from 'react-helmet';
|
2017-02-22 19:29:35 +00:00
|
|
|
import NewPasswordForm from '../components/NewPasswordForm';
|
|
|
|
import * as UserActions from '../actions';
|
2019-09-19 17:38:27 +00:00
|
|
|
import Nav from '../../../components/Nav';
|
2017-02-22 19:29:35 +00:00
|
|
|
|
2019-09-19 17:38:27 +00:00
|
|
|
function NewPasswordView(props) {
|
|
|
|
const newPasswordClass = classNames({
|
|
|
|
'new-password': true,
|
|
|
|
'new-password--invalid': props.user.resetPasswordInvalid,
|
|
|
|
'form-container': true,
|
|
|
|
'user': true
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<div className="new-password-container">
|
|
|
|
<Nav layout="dashboard" />
|
|
|
|
<div className={newPasswordClass}>
|
|
|
|
<Helmet>
|
|
|
|
<title>p5.js Web Editor | New Password</title>
|
|
|
|
</Helmet>
|
|
|
|
<div className="form-container__content">
|
|
|
|
<h2 className="form-container__title">Set a New Password</h2>
|
|
|
|
<NewPasswordForm {...props} />
|
|
|
|
<p className="new-password__invalid">
|
|
|
|
The password reset token is invalid or has expired.
|
|
|
|
</p>
|
2016-12-19 21:49:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-09-19 17:38:27 +00:00
|
|
|
</div>
|
|
|
|
);
|
2016-12-19 21:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NewPasswordView.propTypes = {
|
|
|
|
params: PropTypes.shape({
|
|
|
|
reset_password_token: PropTypes.string,
|
2017-02-22 19:29:35 +00:00
|
|
|
}).isRequired,
|
2016-12-19 21:49:37 +00:00
|
|
|
validateResetPasswordToken: PropTypes.func.isRequired,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
resetPasswordInvalid: PropTypes.bool
|
2017-02-22 19:29:35 +00:00
|
|
|
}).isRequired
|
2016-12-19 21:49:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function validate(formProps) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
if (!formProps.password) {
|
|
|
|
errors.password = 'Please enter a password';
|
|
|
|
}
|
|
|
|
if (!formProps.confirmPassword) {
|
|
|
|
errors.confirmPassword = 'Please enter a password confirmation';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (formProps.password !== formProps.confirmPassword) {
|
|
|
|
errors.password = 'Passwords must match';
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
user: state.user
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return bindActionCreators(UserActions, dispatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default reduxForm({
|
|
|
|
form: 'new-password',
|
|
|
|
fields: ['password', 'confirmPassword'],
|
|
|
|
validate
|
|
|
|
}, mapStateToProps, mapDispatchToProps)(NewPasswordView);
|