- Revert "Improve authentication" and "Default Authentication Method"

to make login work again.
- Fixes to docker-compose.yml so that Wekan Meteor 1.6.x version would work.
  Most likely Meteor 1.8.x version is still broken.

Thanks to xet7 !
This commit is contained in:
Lauri Ojansivu 2018-12-24 18:18:41 +02:00
parent 425ae55422
commit c502ab9500
7 changed files with 107 additions and 82 deletions

View file

@ -9,12 +9,10 @@ Template.editor.onRendered(() => {
match: /\B@([\w.]*)$/, match: /\B@([\w.]*)$/,
search(term, callback) { search(term, callback) {
const currentBoard = Boards.findOne(Session.get('currentBoard')); const currentBoard = Boards.findOne(Session.get('currentBoard'));
if (currentBoard) { callback(currentBoard.activeMembers().map((member) => {
callback(currentBoard.activeMembers().map((member) => { const username = Users.findOne(member.userId).username;
const username = Users.findOne(member.userId).username; return username.includes(term) ? username : null;
return username.includes(term) ? username : null; }).filter(Boolean));
}).filter(Boolean));
}
}, },
template(value) { template(value) {
return value; return value;
@ -39,9 +37,6 @@ const at = HTML.CharRef({html: '@', str: '@'});
Blaze.Template.registerHelper('mentions', new Template('mentions', function() { Blaze.Template.registerHelper('mentions', new Template('mentions', function() {
const view = this; const view = this;
const currentBoard = Boards.findOne(Session.get('currentBoard')); const currentBoard = Boards.findOne(Session.get('currentBoard'));
if (!currentBoard) {
return HTML.Raw('');
}
const knowedUsers = currentBoard.members.map((member) => { const knowedUsers = currentBoard.members.map((member) => {
const u = Users.findOne(member.userId); const u = Users.findOne(member.userId);
if(u){ if(u){

View file

@ -23,6 +23,7 @@ template(name="userFormsLayout")
br br
section.auth-dialog section.auth-dialog
+Template.dynamic(template=content) +Template.dynamic(template=content)
+connectionMethod
if isCas if isCas
.at-form .at-form
button#cas(class='at-btn submit' type='submit') {{casSignInLabel}} button#cas(class='at-btn submit' type='submit') {{casSignInLabel}}

View file

@ -6,14 +6,29 @@ const i18nTagToT9n = (i18nTag) => {
return i18nTag; return i18nTag;
}; };
Template.userFormsLayout.onCreated(function() { const validator = {
Meteor.call('getDefaultAuthenticationMethod', (error, result) => { set(obj, prop, value) {
this.data.defaultAuthenticationMethod = new ReactiveVar(error ? undefined : result); if (prop === 'state' && value !== 'signIn') {
}); $('.at-form-authentication').hide();
} else if (prop === 'state' && value === 'signIn') {
$('.at-form-authentication').show();
}
// The default behavior to store the value
obj[prop] = value;
// Indicate success
return true;
},
};
Template.userFormsLayout.onCreated(() => {
Meteor.subscribe('setting'); Meteor.subscribe('setting');
}); });
Template.userFormsLayout.onRendered(() => { Template.userFormsLayout.onRendered(() => {
AccountsTemplates.state.form.keys = new Proxy(AccountsTemplates.state.form.keys, validator);
const i18nTag = navigator.language; const i18nTag = navigator.language;
if (i18nTag) { if (i18nTag) {
T9n.setLanguage(i18nTagToT9n(i18nTag)); T9n.setLanguage(i18nTagToT9n(i18nTag));
@ -86,11 +101,13 @@ Template.userFormsLayout.events({
} }
}); });
}, },
'click #at-btn'(event, instance) { 'click #at-btn'(event) {
const email = $('#at-field-username_and_email').val(); /* All authentication method can be managed/called here.
const password = $('#at-field-password').val(); !! DON'T FORGET to correctly fill the fields of the user during its creation if necessary authenticationMethod : String !!
*/
if (FlowRouter.getRouteName() !== 'atSignIn' || password === '' || email === '') { const authenticationMethodSelected = $('.select-authentication').val();
// Local account
if (authenticationMethodSelected === 'password') {
return; return;
} }
@ -98,11 +115,29 @@ Template.userFormsLayout.events({
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation(); event.stopImmediatePropagation();
Meteor.subscribe('user-authenticationMethod', email, { const email = $('#at-field-username_and_email').val();
onReady() { const password = $('#at-field-password').val();
return authentication.call(this, instance, email, password);
}, // Ldap account
}); if (authenticationMethodSelected === 'ldap') {
// Check if the user can use the ldap connection
Meteor.subscribe('user-authenticationMethod', email, {
onReady() {
const user = Users.findOne();
if (user === undefined || user.authenticationMethod === 'ldap') {
// Use the ldap connection package
Meteor.loginWithLDAP(email, password, function(error) {
if (!error) {
// Connection
return FlowRouter.go('/');
}
return error;
});
}
return this.stop();
},
});
}
}, },
}); });
@ -111,49 +146,3 @@ Template.defaultLayout.events({
Modal.close(); Modal.close();
}, },
}); });
function authentication(instance, email, password) {
const user = Users.findOne();
// Authentication with password
if (user && user.authenticationMethod === 'password') {
$('#at-pwd-form').submit();
return this.stop();
}
const authenticationMethod = user
? user.authenticationMethod
: instance.data.defaultAuthenticationMethod.get();
switch (authenticationMethod) {
case 'ldap':
// Use the ldap connection package
Meteor.loginWithLDAP(email, password, function(error) {
if (error) {
displayError('error-ldap-login');
return this.stop();
} else {
return FlowRouter.go('/');
}
});
break;
default:
displayError('error-undefined');
}
return this.stop();
}
function displayError(code) {
const translated = TAPi18n.__(code);
if (translated === code) {
return;
}
if(!$('.at-error').length) {
$('.at-pwd-form').before('<div class="at-error"><p></p></div>');
}
$('.at-error p').text(translated);
}

View file

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

View file

@ -0,0 +1,34 @@
Template.connectionMethod.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]})),
]);
}
// If only the default authentication available, hides the select boxe
const content = $('.at-form-authentication');
if (!(this.authenticationMethods.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-authentication').detach().prependTo('.at-pwd-form');
});
Template.connectionMethod.helpers({
authentications() {
return Template.instance().authenticationMethods.get();
},
});

View file

@ -128,17 +128,18 @@ services:
- wekan-tier - wekan-tier
#------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------
# ==== BUILD wekan-app DOCKER CONTAINER FROM SOURCE, if you uncomment these ==== # ==== BUILD wekan-app DOCKER CONTAINER FROM SOURCE, if you uncomment these ====
#build: # ==== and use commands: docker-compose up -d --build
# context: . build:
# dockerfile: Dockerfile context: .
# args: dockerfile: Dockerfile
# - NODE_VERSION=${NODE_VERSION} args:
# - METEOR_RELEASE=${METEOR_RELEASE} - NODE_VERSION=${NODE_VERSION}
# - NPM_VERSION=${NPM_VERSION} - METEOR_RELEASE=${METEOR_RELEASE}
# - ARCHITECTURE=${ARCHITECTURE} - NPM_VERSION=${NPM_VERSION}
# - SRC_PATH=${SRC_PATH} - ARCHITECTURE=${ARCHITECTURE}
# - METEOR_EDGE=${METEOR_EDGE} - SRC_PATH=${SRC_PATH}
# - USE_EDGE=${USE_EDGE} - METEOR_EDGE=${METEOR_EDGE}
- USE_EDGE=${USE_EDGE}
#------------------------------------------------------------------------------------- #-------------------------------------------------------------------------------------
ports: ports:
# Docker outsideport:insideport. Do not add anything extra here. # Docker outsideport:insideport. Do not add anything extra here.

View file

@ -254,7 +254,6 @@ const myCommand :Spk.Manifest.Command = (
(key = "OAUTH2_TOKEN_ENDPOINT", value=""), (key = "OAUTH2_TOKEN_ENDPOINT", value=""),
(key = "LDAP_ENABLE", value="false"), (key = "LDAP_ENABLE", value="false"),
(key = "SANDSTORM", value = "1"), (key = "SANDSTORM", value = "1"),
(key = "METEOR_SETTINGS", value = "{\"public\": {\"sandstorm\": true}}"), (key = "METEOR_SETTINGS", value = "{\"public\": {\"sandstorm\": true}}")
(key = "DEFAULT_AUTHENTICATION_METHOD", value = "")
] ]
); );