From d3e4bb3ed2585859a3adeb7eeff35b7c75ebd840 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 16 Sep 2018 22:40:05 +0200 Subject: auth gate on main app. pull in auth routes from bucky. --- app/client/auth/login.component.js | 86 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 app/client/auth/login.component.js (limited to 'app/client/auth/login.component.js') diff --git a/app/client/auth/login.component.js b/app/client/auth/login.component.js new file mode 100644 index 0000000..4ffab34 --- /dev/null +++ b/app/client/auth/login.component.js @@ -0,0 +1,86 @@ +import { h, Component } from 'preact'; +// import PropTypes from 'prop-types'; +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; +import { Redirect } from 'react-router-dom'; +// import { Link } from 'react-router-dom'; +import * as authActions from './auth.actions'; + +import { Group, Param, TextInput, Button } from '../common'; + +class Login extends Component { + state = { + username: '', + password: '', + } + constructor() { + super() + this.handleChange = this.handleChange.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) + } + handleChange(e) { + const name = e.target.name + const value = e.target.value + this.setState({ + [name]: value, + error: null, + }) + } + handleSubmit(e) { + e.preventDefault() + this.props.actions.login(this.state.username, this.state.password) + } + render(){ + if (this.props.auth.isAuthenticated) { + return + } + return ( +
+

Log in


+ + + + + {this.renderAuthError()} + +
+ ) + } + renderAuthError(){ + if (this.props.auth.error) { + return ( +
{"There was an error logging you in (bad password?)"}
+ ) + } + return null + } +} + +const mapStateToProps = (state) => ({ + auth: state.auth, +}); + +const mapDispatchToProps = (dispatch) => ({ + actions: bindActionCreators(authActions, dispatch) +}); + +export default connect(mapStateToProps, mapDispatchToProps)(Login); -- cgit v1.2.3-70-g09d2