Blame view
imports/client/views/org/enter/login/login.js
1.34 KB
4c9b3dfc1
|
1 |
/* eslint-disable no-undef */ |
7df77f0fa
|
2 |
import { browserHistory } from 'react-router'; |
cac7cbc73
|
3 4 |
import { Meteor } from 'meteor/meteor'; import { Bert } from 'meteor/themeteorchef:bert'; |
cc8fd8a94
|
5 |
import '/imports/client/components/validation'; |
7df77f0fa
|
6 |
|
2b1ad7917
|
7 |
let component; |
db5aba845
|
8 |
|
cac7cbc73
|
9 |
const login = () => { |
23c8a4c3c
|
10 11 |
const email = document.querySelector('[name="emailAddress"]').value; const password = document.querySelector('[name="password"]').value; |
0ccda7775
|
12 |
|
f0c912bf1
|
13 14 15 |
Meteor.loginWithPassword(email, password, (error) => { if (error) { Bert.alert(error.reason, 'warning'); |
c39994410
|
16 |
} else { |
f0c912bf1
|
17 |
Bert.alert('Logged in!', 'success'); |
cac7cbc73
|
18 19 20 21 22 23 24 |
const { location } = component.props; if (location.state && location.state.nextPathname) { browserHistory.push(location.state.nextPathname); } else { browserHistory.push('/'); } |
c39994410
|
25 26 |
} }); |
0ccda7775
|
27 |
}; |
cac7cbc73
|
28 |
const validate = () => { |
4c9b3dfc1
|
29 |
$(component.loginForm).validate({ |
0ccda7775
|
30 31 32 |
rules: { emailAddress: { required: true, |
f0c912bf1
|
33 |
email: true, |
0ccda7775
|
34 35 |
}, password: { |
f0c912bf1
|
36 37 |
required: true, }, |
0ccda7775
|
38 39 40 41 |
}, messages: { emailAddress: { required: 'Need an email address here.', |
f0c912bf1
|
42 |
email: 'Is this email address legit?', |
0ccda7775
|
43 44 |
}, password: { |
f0c912bf1
|
45 46 |
required: 'Need a password here.', }, |
0ccda7775
|
47 |
}, |
cac7cbc73
|
48 |
submitHandler() { login(); }, |
2b1ad7917
|
49 |
}); |
0ccda7775
|
50 |
}; |
23c8a4c3c
|
51 |
export default function handleLogin(options) { |
2b1ad7917
|
52 |
component = options.component; |
cac7cbc73
|
53 |
validate(); |
23c8a4c3c
|
54 |
} |