import React from 'react'; import PropTypes from 'prop-types'; import { Row, Col, Alert, FormGroup, ControlLabel, Button } from 'react-bootstrap'; import { Accounts } from 'meteor/accounts-base'; import { Bert } from 'meteor/themeteorchef:bert'; import validate from '../../../modules/validate'; class ResetPassword extends React.Component { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); } componentDidMount() { const component = this; validate(component.form, { rules: { newPassword: { required: true, minlength: 6, }, repeatNewPassword: { required: true, minlength: 6, equalTo: '[name="newPassword"]', }, }, messages: { newPassword: { required: 'Enter a new password, please.', minlength: 'Use at least six characters, please.', }, repeatNewPassword: { required: 'Repeat your new password, please.', equalTo: 'Hmm, your passwords don\'t match. Try again?', }, }, submitHandler() { component.handleSubmit(); }, }); } handleSubmit() { const { match, history } = this.props; const token = match.params.token; Accounts.resetPassword(token, this.newPassword.value, (error) => { if (error) { Bert.alert(error.reason, 'danger'); } else { history.push('/documents'); } }); } render() { return (

Reset Password

To reset your password, enter a new one below. You will be logged in with your new password.
(this.form = form)} onSubmit={event => event.preventDefault()}> New Password (this.newPassword = newPassword)} name="newPassword" placeholder="New Password" /> Repeat New Password (this.repeatNewPassword = repeatNewPassword)} name="repeatNewPassword" placeholder="Repeat New Password" />
); } } ResetPassword.propTypes = { match: PropTypes.object.isRequired, history: PropTypes.object.isRequired, }; export default ResetPassword;