Blame view
imports/modules/signup.js
1.52 KB
7df77f0fa
|
1 2 3 4 |
import { browserHistory } from 'react-router'; import { getInputValue } from './get-input-value'; let component; |
f0c912bf1
|
5 6 7 8 9 10 11 12 13 14 |
const _getUserData = () => ({ email: getInputValue(component, 'emailAddress', true), password: getInputValue(component, 'password', true), profile: { name: { first: getInputValue(component, 'firstName', true), last: getInputValue(component, 'lastName', true), }, }, }); |
7df77f0fa
|
15 16 17 |
const _handleSignup = () => { const user = _getUserData(); |
f0c912bf1
|
18 19 20 |
Accounts.createUser(user, (error) => { if (error) { Bert.alert(error.reason, 'danger'); |
7df77f0fa
|
21 |
} else { |
f0c912bf1
|
22 23 |
browserHistory.push('/'); Bert.alert('Welcome!', 'success'); |
7df77f0fa
|
24 25 26 27 28 |
} }); }; const _validate = () => { |
f0c912bf1
|
29 |
$(component.refs.signup).validate({ |
7df77f0fa
|
30 31 |
rules: { firstName: { |
f0c912bf1
|
32 |
required: true, |
7df77f0fa
|
33 34 |
}, lastName: { |
f0c912bf1
|
35 |
required: true, |
7df77f0fa
|
36 37 38 |
}, emailAddress: { required: true, |
f0c912bf1
|
39 |
email: true, |
7df77f0fa
|
40 41 42 |
}, password: { required: true, |
f0c912bf1
|
43 44 |
minlength: 6, }, |
7df77f0fa
|
45 46 47 |
}, messages: { firstName: { |
f0c912bf1
|
48 |
required: 'First name?', |
7df77f0fa
|
49 50 |
}, lastName: { |
f0c912bf1
|
51 |
required: 'Last name?', |
7df77f0fa
|
52 53 54 |
}, emailAddress: { required: 'Need an email address here.', |
f0c912bf1
|
55 |
email: 'Is this email address legit?', |
7df77f0fa
|
56 57 58 |
}, password: { required: 'Need a password here.', |
f0c912bf1
|
59 60 |
minlength: 'Use at least six characters, please.', }, |
7df77f0fa
|
61 |
}, |
f0c912bf1
|
62 |
submitHandler() { _handleSignup(); }, |
7df77f0fa
|
63 64 |
}); }; |
f0c912bf1
|
65 |
export const handleSignup = (options) => { |
7df77f0fa
|
66 67 68 |
component = options.component; _validate(); }; |