-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatTextInputWithPasswordStrength.js
53 lines (48 loc) · 1.68 KB
/
atTextInputWithPasswordStrength.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
getPasswordStrength
} from './useraccounts-password-strength.js';
const enabledStatesArr = ["enrollAccount", "signUp", "resetPwd", "changePwd"];
Template.atForm.onCreated(function() {
if (typeof this.data.state !== 'undefined') {
if (enabledStatesArr.indexOf(this.data.state) > -1) {
AccountsTemplates.setState(this.data.state);
}
}
});
Template.atTextInputWithPasswordStrength.onCreated(function() {
this.strength = ReactiveVar(0);
this.strengthText = ReactiveVar('');
});
Template.atTextInputWithPasswordStrength.helpers({
showStrengthLevel: function() {
return enabledStatesArr.indexOf(AccountsTemplates.getState()) > -1;
},
strength: function() {
return Template.instance().strength.get();
},
strengthText: function() {
return Template.instance().strengthText.get();
},
strengthClassName: function(strengthLevel) {
var strength = Template.instance().strength.get();
if (strengthLevel > (strength + 1)) {
return 'strengthLevelNone';
} else if (strength <= 1) {
return 'strengthLevelLow';
} else if (strength <= 2) {
return 'strengthLevelMedium';
} else if (strength <= 3) {
return 'strengthLevelHigh';
} else {
return 'strengthLevelStrong';
}
}
});
Template.atTextInputWithPasswordStrength.events({
"keyup input": function(event, templateInstance) {
var password = $(event.target).val();
var result = getPasswordStrength(password);
templateInstance.strength.set(result.strength);
templateInstance.strengthText.set(result.strengthText);
},
});