2016-12-15 23:43:58 +00:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import { reduxForm } from 'redux-form';
|
2017-02-22 19:29:35 +00:00
|
|
|
import { Link, browserHistory } from 'react-router';
|
|
|
|
import InlineSVG from 'react-inlinesvg';
|
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';
|
2017-04-13 16:04:10 +00:00
|
|
|
import GithubButton from '../components/GithubButton';
|
|
|
|
|
2016-12-15 23:43:58 +00:00
|
|
|
const exitUrl = require('../../../images/exit.svg');
|
|
|
|
const logoUrl = require('../../../images/p5js-logo.svg');
|
|
|
|
|
|
|
|
|
|
|
|
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 (
|
|
|
|
<div className="form-container">
|
|
|
|
<div className="form-container__header">
|
|
|
|
<button className="form-container__logo-button" onClick={this.gotoHomePage}>
|
|
|
|
<InlineSVG src={logoUrl} alt="p5js Logo" />
|
|
|
|
</button>
|
|
|
|
<button className="form-container__exit-button" onClick={this.closeLoginPage}>
|
|
|
|
<InlineSVG src={exitUrl} alt="Close Login Page" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="form-container__content">
|
|
|
|
<h2 className="form-container__title">Log In</h2>
|
|
|
|
<LoginForm {...this.props} />
|
2017-04-13 16:04:10 +00:00
|
|
|
<h2 className="form-container__divider">Or</h2>
|
|
|
|
<GithubButton buttonText="Login with Github" />
|
2016-12-15 23:43:58 +00:00
|
|
|
<p className="form__navigation-options">
|
2017-02-22 19:29:35 +00:00
|
|
|
Don't have an account?
|
2016-12-15 23:43:58 +00:00
|
|
|
<Link className="form__signup-button" to="/signup">Sign Up</Link>
|
|
|
|
</p>
|
|
|
|
<p className="form__navigation-options">
|
|
|
|
Forgot your password?
|
|
|
|
<Link className="form__reset-password-button" to="/reset-password">Reset your password</Link>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
user: {
|
|
|
|
authenticated: PropTypes.bool
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LoginView.defaultProps = {
|
|
|
|
user: {
|
|
|
|
authenticated: false
|
|
|
|
}
|
2016-12-15 23:43:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default reduxForm({
|
|
|
|
form: 'login',
|
|
|
|
fields: ['email', 'password'],
|
2017-03-16 22:25:12 +00:00
|
|
|
validate: validateLogin
|
2016-12-15 23:43:58 +00:00
|
|
|
}, mapStateToProps, mapDispatchToProps)(LoginView);
|