Blame view
imports/client/app/utils/reset-password.js
1.34 KB
c4d3e07d0
|
1 2 |
import $ from 'jquery'; import 'jquery-validation'; |
7df77f0fa
|
3 |
import { browserHistory } from 'react-router'; |
cac7cbc73
|
4 5 |
import { Accounts } from 'meteor/accounts-base'; import { Bert } from 'meteor/themeteorchef:bert'; |
c4d3e07d0
|
6 |
import { getInputValue } from './get-input-value'; |
7df77f0fa
|
7 |
|
f0c912bf1
|
8 9 |
let component; let token; |
7df77f0fa
|
10 |
|
cac7cbc73
|
11 |
const handleReset = () => { |
c4d3e07d0
|
12 |
const password = getInputValue(component.refs.newPassword); |
f0c912bf1
|
13 14 15 |
Accounts.resetPassword(token, password, (error) => { if (error) { Bert.alert(error.reason, 'danger'); |
7df77f0fa
|
16 |
} else { |
f0c912bf1
|
17 18 |
browserHistory.push('/'); Bert.alert('Password reset!', 'success'); |
7df77f0fa
|
19 20 21 |
} }); }; |
cac7cbc73
|
22 |
const validate = () => { |
c4d3e07d0
|
23 |
$(component.refs.resetPassword).validate({ |
7df77f0fa
|
24 25 26 |
rules: { newPassword: { required: true, |
f0c912bf1
|
27 |
minlength: 6, |
7df77f0fa
|
28 29 30 31 |
}, repeatNewPassword: { required: true, minlength: 6, |
f0c912bf1
|
32 33 |
equalTo: '[name="newPassword"]', }, |
7df77f0fa
|
34 35 36 |
}, messages: { newPassword: { |
f0c912bf1
|
37 38 |
required: 'Enter a new password, please.', minlength: 'Use at least six characters, please.', |
7df77f0fa
|
39 40 |
}, repeatNewPassword: { |
f0c912bf1
|
41 42 43 |
required: 'Repeat your new password, please.', equalTo: 'Hmm, your passwords don\'t match. Try again?', }, |
7df77f0fa
|
44 |
}, |
cac7cbc73
|
45 |
submitHandler() { handleReset(); }, |
7df77f0fa
|
46 47 |
}); }; |
c4d3e07d0
|
48 |
export const handleResetPassword = (options) => { |
7df77f0fa
|
49 |
component = options.component; |
f0c912bf1
|
50 |
token = options.token; |
cac7cbc73
|
51 |
validate(); |
c4d3e07d0
|
52 |
}; |