-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
75 lines (72 loc) · 2.38 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { h, Component } from 'preact';
import { route } from 'preact-router';
import LayoutGrid from 'preact-material-components/LayoutGrid';
import Button from 'preact-material-components/Button';
import TextField from 'preact-material-components/TextField';
import FormField from 'preact-material-components/FormField';
import Card from 'preact-material-components/Card';
import 'preact-material-components/LayoutGrid/style.css';
import 'preact-material-components/TextField/style.css';
import 'preact-material-components/FormField/style.css';
import 'preact-material-components/Button/style.css';
import 'preact-material-components/Card/style.css';
import reduce from '../../reducers';
import store from '../../store';
import * as actions from '../../actions';
import { connect } from 'preact-redux';
import { account } from '../../common/config'
import style from './style';
function login(){
var fd = new FormData(document.getElementById("login"));
fetch(account()+"/account/login", {
method: "POST",
body: fd,
cors: true,
}).then((resp) => {
return resp.json();
}).then((data) => {
store.dispatch(
actions.authenticated(data.success)
)
}).catch((error) => {
console.log(error);
})
}
@connect(reduce, actions)
export default class Login extends Component {
submit = (event) => {
event.preventDefault();
login();
return false;
}
render = ({ ...state }, { text }) => {
return (
<div className="login page">
<LayoutGrid>
<LayoutGrid.Inner>
<LayoutGrid.Cell cols="6" desktopCols="6" tabletCols="8" phoneCols="4">
<Card style={{"background-color": "#FFFFFF"}}>
<Card.Primary>
<Card.Title>Login</Card.Title>
</Card.Primary>
<Card.Media className='card-media'>
<form id="login" onsubmit={this.submit}>
<TextField type="text" name="email" placeholder="Email" fullwidth={true} />
<TextField type="password" name="password" placeholder="Password" fullwidth={true}/>
<br />
<Button raised={true}>Login</Button>
</form>
</Card.Media>
<Card.Actions>
<Card.Action onclick={() => ( route("/register", true) ) }>
Register a new account
</Card.Action>
</Card.Actions>
</Card>
</LayoutGrid.Cell>
</LayoutGrid.Inner>
</LayoutGrid>
</div>
);
};
}