2018-02-07 18:06:07 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-12-15 23:43:58 +00:00
|
|
|
import { reduxForm } from 'redux-form';
|
2017-02-22 19:29:35 +00:00
|
|
|
import { Link, browserHistory } from 'react-router';
|
2018-02-23 16:31:41 +00:00
|
|
|
import { Helmet } from 'react-helmet';
|
2020-08-12 14:24:29 +00:00
|
|
|
import { withTranslation } from 'react-i18next';
|
|
|
|
import i18n from 'i18next';
|
2016-12-15 23:43:58 +00:00
|
|
|
import { validateAndLoginUser } from '../actions';
|
|
|
|
import LoginForm from '../components/LoginForm';
|
2017-03-16 22:25:12 +00:00
|
|
|
import { validateLogin } from '../../../utils/reduxFormUtils';
|
2020-04-19 20:45:09 +00:00
|
|
|
import SocialAuthButton from '../components/SocialAuthButton';
|
2019-09-19 17:38:27 +00:00
|
|
|
import Nav from '../../../components/Nav';
|
2020-08-21 18:09:50 +00:00
|
|
|
import ResponsiveForm from '../components/ResponsiveForm';
|
2016-12-15 23:43:58 +00:00
|
|
|
|
|
|
|
class LoginView extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.closeLoginPage = this.closeLoginPage.bind(this);
|
|
|
|
this.gotoHomePage = this.gotoHomePage.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
closeLoginPage() {
|
|
|
|
browserHistory.push(this.props.previousPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
gotoHomePage() {
|
|
|
|
browserHistory.push('/');
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-09-29 18:52:20 +00:00
|
|
|
if (this.props.user.authenticated) {
|
|
|
|
this.gotoHomePage();
|
|
|
|
return null;
|
|
|
|
}
|
2016-12-15 23:43:58 +00:00
|
|
|
return (
|
2020-08-21 20:03:04 +00:00
|
|
|
<div className="login">
|
|
|
|
<Nav layout="dashboard" />
|
|
|
|
<main className="form-container">
|
|
|
|
<Helmet>
|
|
|
|
<title>{this.props.t('LoginView.Title')}</title>
|
|
|
|
</Helmet>
|
|
|
|
<div className="form-container__content">
|
|
|
|
<h2 className="form-container__title">{this.props.t('LoginView.Login')}</h2>
|
|
|
|
<LoginForm {...this.props} />
|
2020-09-07 11:59:15 +00:00
|
|
|
{/* <h2 className="form-container__divider">{this.props.t('LoginView.LoginOr')}</h2>
|
2020-08-21 20:03:04 +00:00
|
|
|
<div className="form-container__stack">
|
|
|
|
<SocialAuthButton service={SocialAuthButton.services.github} />
|
|
|
|
<SocialAuthButton service={SocialAuthButton.services.google} />
|
2020-09-07 11:59:15 +00:00
|
|
|
</div> */}
|
2020-08-21 20:03:04 +00:00
|
|
|
<p className="form__navigation-options">
|
|
|
|
{this.props.t('LoginView.DontHaveAccount')}
|
|
|
|
<Link className="form__signup-button" to="/signup">{this.props.t('LoginView.SignUp')}</Link>
|
|
|
|
</p>
|
|
|
|
<p className="form__navigation-options">
|
|
|
|
{this.props.t('LoginView.ForgotPassword')}
|
|
|
|
<Link className="form__reset-password-button" to="/reset-password"> {this.props.t('LoginView.ResetPassword')}</Link>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
</div>
|
2016-12-15 23:43:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
user: state.user,
|
|
|
|
previousPath: state.ide.previousPath
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps() {
|
|
|
|
return {
|
|
|
|
validateAndLoginUser
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
LoginView.propTypes = {
|
2017-09-29 18:52:20 +00:00
|
|
|
previousPath: PropTypes.string.isRequired,
|
2019-09-06 17:30:06 +00:00
|
|
|
user: PropTypes.shape({
|
2017-09-29 18:52:20 +00:00
|
|
|
authenticated: PropTypes.bool
|
2020-08-12 14:24:29 +00:00
|
|
|
}),
|
2020-08-21 18:09:50 +00:00
|
|
|
t: PropTypes.func.isRequired,
|
2017-09-29 18:52:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LoginView.defaultProps = {
|
|
|
|
user: {
|
|
|
|
authenticated: false
|
2020-08-21 18:09:50 +00:00
|
|
|
},
|
2016-12-15 23:43:58 +00:00
|
|
|
};
|
|
|
|
|
2020-08-12 14:24:29 +00:00
|
|
|
export default withTranslation()(reduxForm({
|
2016-12-15 23:43:58 +00:00
|
|
|
form: 'login',
|
|
|
|
fields: ['email', 'password'],
|
2017-03-16 22:25:12 +00:00
|
|
|
validate: validateLogin
|
2020-08-12 14:24:29 +00:00
|
|
|
}, mapStateToProps, mapDispatchToProps)(LoginView));
|