2016-11-23 18:40:35 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import { h, render, Component } from 'preact';
|
2016-12-08 11:27:19 +00:00
|
|
|
import Client from '../lib/client.js';
|
2016-11-23 18:40:35 +00:00
|
|
|
|
|
|
|
class LoginForm extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
2016-12-08 11:27:19 +00:00
|
|
|
this.state = {
|
2016-11-23 18:40:35 +00:00
|
|
|
email: '',
|
|
|
|
password: '',
|
2016-12-08 11:27:19 +00:00
|
|
|
}
|
2016-11-23 18:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2016-12-08 11:27:19 +00:00
|
|
|
Client.request('session', {
|
2016-11-23 18:40:35 +00:00
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
email: this.state.email,
|
|
|
|
password: this.state.password,
|
|
|
|
}
|
2016-12-08 11:27:19 +00:00
|
|
|
}).then((r) => { this.props.onSuccess() })
|
2016-11-23 18:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="block">
|
|
|
|
<h2>Login</h2>
|
|
|
|
<p>Please enter your credentials to access your Ana dashboard.</p>
|
|
|
|
<form method="POST" onSubmit={this.handleSubmit}>
|
2016-11-24 12:10:40 +00:00
|
|
|
<div class="small-margin">
|
2016-11-23 18:40:35 +00:00
|
|
|
<label>Email address</label>
|
2016-11-25 12:38:20 +00:00
|
|
|
<input type="email" name="email" placeholder="Email address" onChange={this.linkState('email')} required="required" />
|
2016-11-23 18:40:35 +00:00
|
|
|
</div>
|
2016-11-24 12:10:40 +00:00
|
|
|
<div class="small-margin">
|
2016-11-23 18:40:35 +00:00
|
|
|
<label>Password</label>
|
2016-11-25 12:38:20 +00:00
|
|
|
<input type="password" name="password" placeholder="**********" onChange={this.linkState('password')} required="required" />
|
2016-11-23 18:40:35 +00:00
|
|
|
</div>
|
2016-11-24 12:10:40 +00:00
|
|
|
<div class="small-margin">
|
2016-11-23 18:40:35 +00:00
|
|
|
<input type="submit" value="Sign in" />
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LoginForm
|