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