/* eslint-disable import/no-absolute-path */ import React from 'react'; import PropTypes from 'prop-types'; import { Row, FormGroup, ControlLabel, Button } from 'react-bootstrap'; import { Link } from 'react-router-dom'; import { Meteor } from 'meteor/meteor'; import { Bert } from 'meteor/themeteorchef:bert'; import { Helmet } from 'react-helmet'; import { translate } from 'react-i18next'; import { T9n } from 'meteor-accounts-t9n'; import { testId } from '/imports/ui/components/Utils/TestUtils'; import Col from '../../components/Col/Col'; import OAuthLoginButtons from '../../components/OAuthLoginButtons/OAuthLoginButtons'; import AccountPageFooter from '../../components/AccountPageFooter/AccountPageFooter'; import validate from '../../../modules/validate'; class Login extends React.Component { constructor(props) { super(props); this.t = props.t; this.handleSubmit = this.handleSubmit.bind(this); // console.log(this.props.location.state); this.state = props.location.state; } componentDidMount() { const component = this; validate(component.form, { rules: { emailAddress: { required: true, email: true }, password: { required: true } }, messages: { emailAddress: { required: this.t('Necesitamos un correo aquí.'), email: this.t('¿Es este correo correcto?') }, password: { required: this.t('Necesitamos una contraseña aquí.') } }, submitHandler() { component.handleSubmit(); } }); } handleSubmit = () => { const { history, i18n } = this.props; Meteor.loginWithPassword(this.emailAddress.value, this.password.value, (error) => { if (error) { Bert.alert(T9n.get(`error.accounts.${error.reason}`), 'danger'); } else { Bert.alert(this.t('Bienvenid@ de nuevo'), 'success'); const userLang = Meteor.user().lang if (typeof userLang === 'string' && i18n.language !== userLang) { i18n.changeLanguage(userLang); } } }); } render() { return (