forked from JackAdams/meteor-accounts-ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldap_client.js
executable file
·86 lines (76 loc) · 2.15 KB
/
ldap_client.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
LDAP = {
data : function () { return null; },
username : function () { return ''; }
};
var firstAttempt = new ReactiveVar(true);
var showForm = new ReactiveVar(false);
var customFormTemplate = new ReactiveVar('');
LDAP.customFormTemplate = customFormTemplate;
LDAP.formHelpers = {
failedLogin : function () {
return !firstAttempt.get(); //return true if more than one attempt has been made. Show Error Message
}
};
LDAP.formEvents = {
'click #login-buttons-password': function(e, tpl) {
initLogin(e,tpl);
},
'keyup input' : function (e, tpl){
if (e.keyCode == 13){ //If Enter Key Pressed
initLogin(e,tpl);
}
},
'click #login-buttons-logout': function(e) {
firstAttempt.set(true);
Meteor.logout(function() {
showForm.set(false);
});
}
};
Meteor.loginWithLdap = function (username, password, callback) {
var methodArguments = {username: username, pwd: password, ldap: true, data: LDAP.data()};
Accounts.callLoginMethod({
methodArguments: [methodArguments],
validateResult: function (result) {
},
userCallback: callback
});
};
Template.ldapLogin.helpers(LDAP.formHelpers);
Template.ldapLogin.events(LDAP.formEvents);
Template.ldapLoginButtons.helpers({
showForm : function () {
return showForm.get();
},
template : function () {
return !!Template[LDAP.customFormTemplate.get()] && LDAP.customFormTemplate.get() || "";
},
usernameOrEmail : function () {
return LDAP.username() || this.username || (this.emails && this.emails[0] && this.emails[0].address) || 'Authenticated user';
}
});
Template.ldapLoginButtons.events({
'click .login-close-text' : function () {
showForm.set(false);
},
'click .login-link-text' : function () {
showForm.set(true);
}
});
// Initiate Login Process:
initLogin = function(e, tpl) {
firstAttempt.set(true);
var username = $(tpl.find('input[name="ldap"]')).val();
var password = $(tpl.find('input[name="password"]')).val();
var result = Meteor.loginWithLdap(username, password, function() {
if (Meteor.userId()) {
showForm.set(false);
return true;
}
else {
firstAttempt.set(false);
return false;
}
});
return result;
};