forked from UK-AS-HIVE/meteor-accounts-ldap
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathldap_client.js
executable file
·49 lines (44 loc) · 1.13 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
var firstAttempt = true;
Template.ldapLogin.events({
'click button[name="login"]': function(e, tpl) {
initLogin(e, tpl);
},
'keyup input': function(e, tpl) {
if (e.keyCode == 13) { //If Enter Key Pressed
initLogin(e, tpl)
}
},
'click button[name="logout"]': function(e) {
firstAttempt = true;
Meteor.logout();
}
});
Meteor.loginWithLdap = function(username, password, callback) {
Accounts.callLoginMethod({
methodArguments: [{
username: username,
pass: password,
ldap: true
}],
validateResult: function(result) {},
userCallback: callback
});
};
Template.ldapLogin.helpers({
failedLogin: function() {
return !firstAttempt; //return true if more than one attempt has been made. Show Error Message
}
})
// Initiate Login Process:
initLogin = function(e, tpl) {
firstAttempt = false;
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())
return true;
else
return false
});
return result;
}