- Add LDAP. In progress.

Thanks to maximest-pierre, Akuket and xet.

Related #119
This commit is contained in:
Lauri Ojansivu 2018-10-03 11:50:52 +03:00
parent 18a1d4c5c6
commit 288800eafc
9 changed files with 139 additions and 4 deletions

View file

@ -18,6 +18,7 @@ template(name="userFormsLayout")
img(src="{{pathFor '/wekan-logo.png'}}" alt="Wekan")
section.auth-dialog
+Template.dynamic(template=content)
+connectionMethod
if isCas
.at-form
button#cas(class='at-btn submit' type='submit') {{casSignInLabel}}

View file

@ -39,7 +39,7 @@ Template.userFormsLayout.helpers({
const curLang = T9n.getLanguage() || 'en';
return t9nTag === curLang;
},
/*
isCas() {
return Meteor.settings.public &&
Meteor.settings.public.cas &&
@ -49,6 +49,7 @@ Template.userFormsLayout.helpers({
casSignInLabel() {
return TAPi18n.__('casSignIn', {}, T9n.getLanguage() || 'en');
},
*/
});
Template.userFormsLayout.events({
@ -64,6 +65,44 @@ Template.userFormsLayout.events({
}
});
},
'submit form'(event) {
const connectionMethod = $('.select-connection').val();
// Local account
if (connectionMethod === 'default') {
return;
}
// TODO : find a way to block "submit #at-pwd-form" of the at_pwd_form.js
const inputs = event.target.getElementsByTagName('input');
const email = inputs.namedItem('at-field-username_and_email').value;
const password = inputs.namedItem('at-field-password').value;
// Ldap account
if (connectionMethod === 'ldap') {
// Check if the user can use the ldap connection
Meteor.subscribe('user-connection-method', email, {
onReady() {
const ldap = Users.findOne();
if (ldap) {
// Use the ldap connection package
Meteor.loginWithLDAP(email, password, function(error) {
if (!error) {
// Connection
return FlowRouter.go('/');
} else {
return error;
}
});
}
return this.stop();
},
});
}
},
});
Template.defaultLayout.events({

View file

@ -0,0 +1,6 @@
template(name='connectionMethod')
div.at-form-connection
label Authentication method
select.select-connection
each connections
option(value="{{value}}") {{_ value}}

View file

@ -0,0 +1,34 @@
Template.connectionMethod.onCreated(function() {
this.connectionMethods = new ReactiveVar([]);
Meteor.call('getConnectionsEnabled', (_, result) => {
if (result) {
// TODO : add a management of different languages
// (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
this.connectionMethods.set([
{value: 'default'},
// Gets only the connection methods availables
...Object.entries(result).filter((e) => e[1]).map((e) => ({value: e[0]})),
]);
}
// If only the default authentication available, hides the select boxe
const content = $('.at-form-connection');
if (!(this.connectionMethods.get().length > 1)) {
content.hide();
} else {
content.show();
}
});
});
Template.connectionMethod.onRendered(() => {
// Moves the select boxe in the first place of the at-pwd-form div
$('.at-form-connection').detach().prependTo('.at-pwd-form');
});
Template.connectionMethod.helpers({
connections() {
return Template.instance().connectionMethods.get();
},
});