import React from 'react'; import PropTypes from 'prop-types'; import { Row, Alert, FormGroup, ControlLabel, Button } from 'react-bootstrap'; import Col from '../../components/Col/Col'; import { Accounts } from 'meteor/accounts-base'; import { Bert } from 'meteor/themeteorchef:bert'; import { Helmet } from 'react-helmet'; import validate from '../../../modules/validate'; import { translate } from 'react-i18next'; import { T9n } from 'meteor-accounts-t9n'; class ResetPassword extends React.Component { constructor(props) { super(props); this.t = props.t; 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: this.t("Introduce una nueva contraseña, por favor."), minlength: this.t("Usa al menos seis caracteres."), }, repeatNewPassword: { required: this.t("Repite tu nueva contraseña, por favor."), equalTo: this.t("Mmmm, tus contraseñas no coinciden. ¿Inténtalo otra vez?"), minlength: this.t("Usa al menos seis caracteres."), }, }, 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(T9n.get(`error.accounts.${error.reason}`), 'danger'); } else { history.push('/subscriptions'); } }); } render() { return (