Blame view

imports/modules/recover-password.js 980 Bytes
cac7cbc73   tmcdeveloper   4.1.0 release
1
2
3
4
  import $ from 'jquery';
  import 'jquery-validation';
  import { Accounts } from 'meteor/accounts-base';
  import { Bert } from 'meteor/themeteorchef:bert';
7df77f0fa   tmcdeveloper   finish wiring up ...
5
6
7
  import { getInputValue } from './get-input-value';
  
  let component;
cac7cbc73   tmcdeveloper   4.1.0 release
8
  const handleRecovery = () => {
7df77f0fa   tmcdeveloper   finish wiring up ...
9
    Accounts.forgotPassword({
cac7cbc73   tmcdeveloper   4.1.0 release
10
      email: getInputValue(component.refs.emailAddress),
f0c912bf1   tmcdeveloper   add method tests ...
11
12
13
    }, (error) => {
      if (error) {
        Bert.alert(error.reason, 'warning');
7df77f0fa   tmcdeveloper   finish wiring up ...
14
      } else {
f0c912bf1   tmcdeveloper   add method tests ...
15
        Bert.alert('Check your inbox for a reset link!', 'success');
7df77f0fa   tmcdeveloper   finish wiring up ...
16
17
18
      }
    });
  };
cac7cbc73   tmcdeveloper   4.1.0 release
19
  const validate = () => {
f0c912bf1   tmcdeveloper   add method tests ...
20
    $(component.refs.recoverPassword).validate({
7df77f0fa   tmcdeveloper   finish wiring up ...
21
22
23
      rules: {
        emailAddress: {
          required: true,
f0c912bf1   tmcdeveloper   add method tests ...
24
25
          email: true,
        },
7df77f0fa   tmcdeveloper   finish wiring up ...
26
27
28
29
      },
      messages: {
        emailAddress: {
          required: 'Need an email address here.',
f0c912bf1   tmcdeveloper   add method tests ...
30
31
          email: 'Is this email address legit?',
        },
7df77f0fa   tmcdeveloper   finish wiring up ...
32
      },
cac7cbc73   tmcdeveloper   4.1.0 release
33
      submitHandler() { handleRecovery(); },
7df77f0fa   tmcdeveloper   finish wiring up ...
34
35
    });
  };
f0c912bf1   tmcdeveloper   add method tests ...
36
  export const handleRecoverPassword = (options) => {
7df77f0fa   tmcdeveloper   finish wiring up ...
37
    component = options.component;
cac7cbc73   tmcdeveloper   4.1.0 release
38
    validate();
7df77f0fa   tmcdeveloper   finish wiring up ...
39
  };