add ldap support | simplify authentications

This commit is contained in:
guillaume 2018-10-09 14:14:39 +02:00
parent 5b8c642d8f
commit 3b4f285fea
15 changed files with 493 additions and 49 deletions

View file

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

View file

@ -1,20 +1,20 @@
Template.connectionMethod.onCreated(function() {
this.connectionMethods = new ReactiveVar([]);
this.authenticationMethods = new ReactiveVar([]);
Meteor.call('getConnectionsEnabled', (_, result) => {
Meteor.call('getAuthenticationsEnabled', (_, 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
this.authenticationMethods.set([
{value: 'password'},
// Gets only the authentication 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)) {
const content = $('.at-form-authentication');
if (!(this.authenticationMethods.get().length > 1)) {
content.hide();
} else {
content.show();
@ -24,11 +24,11 @@ Template.connectionMethod.onCreated(function() {
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');
$('.at-form-authentication').detach().prependTo('.at-pwd-form');
});
Template.connectionMethod.helpers({
connections() {
return Template.instance().connectionMethods.get();
authentications() {
return Template.instance().authenticationMethods.get();
},
});
});

View file

@ -27,6 +27,7 @@ template(name="peopleGeneral")
th {{_ 'verified'}}
th {{_ 'createdAt'}}
th {{_ 'active'}}
th {{_ 'authentication-method'}}
th
each user in peopleList
+peopleRow(userId=user._id)
@ -52,6 +53,7 @@ template(name="peopleRow")
| {{_ 'no'}}
else
| {{_ 'yes'}}
td {{_ userData.authenticationMethod }}
td
a.edit-user
| {{_ 'edit'}}
@ -66,12 +68,18 @@ template(name="editUserPopup")
| {{_ 'username'}}
span.error.hide.username-taken
| {{_ 'error-username-taken'}}
input.js-profile-username(type="text" value=user.username)
if isLdap
input.js-profile-username(type="text" value=user.username readonly)
else
input.js-profile-username(type="text" value=user.username)
label
| {{_ 'email'}}
span.error.hide.email-taken
| {{_ 'error-email-taken'}}
input.js-profile-email(type="email" value="{{user.emails.[0].address}}")
if isLdap
input.js-profile-email(type="email" value="{{user.emails.[0].address}}" readonly)
else
input.js-profile-email(type="email" value="{{user.emails.[0].address}}")
label
| {{_ 'admin'}}
select.select-role.js-profile-isadmin
@ -82,9 +90,17 @@ template(name="editUserPopup")
select.select-active.js-profile-isactive
option(value="false") {{_ 'yes'}}
option(value="true" selected="{{user.loginDisabled}}") {{_ 'no'}}
label
| {{_ 'authentication-type'}}
select.select-authenticationMethod.js-authenticationMethod
each authentications
if isSelected value
option(value="{{value}}" selected) {{_ value}}
else
option(value="{{value}}") {{_ value}}
hr
label
| {{_ 'password'}}
input.js-profile-password(type="password")
input.primary.wide(type="submit" value="{{_ 'save'}}")
input.primary.wide(type="submit" value="{{_ 'save'}}")

View file

@ -62,10 +62,39 @@ Template.peopleRow.helpers({
},
});
Template.editUserPopup.onCreated(function() {
this.authenticationMethods = new ReactiveVar([]);
Meteor.call('getAuthenticationsEnabled', (_, result) => {
if (result) {
// TODO : add a management of different languages
// (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
this.authenticationMethods.set([
{value: 'password'},
// Gets only the authentication methods availables
...Object.entries(result).filter(e => e[1]).map(e => ({value: e[0]})),
]);
}
});
});
Template.editUserPopup.helpers({
user() {
return Users.findOne(this.userId);
},
authentications() {
return Template.instance().authenticationMethods.get();
},
isSelected(match) {
const userId = Template.instance().data.userId;
const selected = Users.findOne(userId).authenticationMethod;
return selected === match;
},
isLdap() {
const userId = Template.instance().data.userId;
const selected = Users.findOne(userId).authenticationMethod;
return selected === 'ldap';
}
});
BlazeComponent.extendComponent({
@ -91,6 +120,7 @@ Template.editUserPopup.events({
const isAdmin = tpl.find('.js-profile-isadmin').value.trim();
const isActive = tpl.find('.js-profile-isactive').value.trim();
const email = tpl.find('.js-profile-email').value.trim();
const authentication = tpl.find('.js-authenticationMethod').value.trim();
const isChangePassword = password.length > 0;
const isChangeUserName = username !== user.username;
@ -101,6 +131,7 @@ Template.editUserPopup.events({
'profile.fullname': fullname,
'isAdmin': isAdmin === 'true',
'loginDisabled': isActive === 'true',
'authenticationMethod': authentication
},
});