diff options
author | Lauri Ojansivu <x@xet7.org> | 2019-02-08 12:33:39 +0200 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2019-02-08 12:33:39 +0200 |
commit | 7125357a4440f5c95ae6c8f5bcd92fdfdbefa397 (patch) | |
tree | 19e21456f5ee10e444ad055b7761235d1e78661f /client/components/main/layouts.js | |
parent | 329c8d64a824f12b1352dc2f6277ee08e1c4df58 (diff) | |
parent | ec453b89b8238adcbb9334e1d006675aa8a7fe06 (diff) | |
download | wekan-7125357a4440f5c95ae6c8f5bcd92fdfdbefa397.tar.gz wekan-7125357a4440f5c95ae6c8f5bcd92fdfdbefa397.tar.bz2 wekan-7125357a4440f5c95ae6c8f5bcd92fdfdbefa397.zip |
Merge remote-tracking branch 'upstream/feature-improve-authentication' into feature-improve-authentication
Diffstat (limited to 'client/components/main/layouts.js')
-rw-r--r-- | client/components/main/layouts.js | 132 |
1 files changed, 72 insertions, 60 deletions
diff --git a/client/components/main/layouts.js b/client/components/main/layouts.js index a50d167e..6f7c914a 100644 --- a/client/components/main/layouts.js +++ b/client/components/main/layouts.js @@ -20,13 +20,19 @@ const validator = { }, }; -Template.userFormsLayout.onCreated(() => { - Meteor.subscribe('setting'); - +Template.userFormsLayout.onCreated(function() { + const instance = this; + instance.currentSetting = new ReactiveVar(); + + Meteor.subscribe('setting', { + onReady() { + instance.currentSetting.set(Settings.findOne()); + return this.stop(); + }, + }); }); Template.userFormsLayout.onRendered(() => { - AccountsTemplates.state.form.keys = new Proxy(AccountsTemplates.state.form.keys, validator); const i18nTag = navigator.language; @@ -37,12 +43,10 @@ Template.userFormsLayout.onRendered(() => { }); Template.userFormsLayout.helpers({ - currentSetting() { - return Settings.findOne(); + return Template.instance().currentSetting.get(); }, - afterBodyStart() { return currentSetting.customHTMLafterBodyStart; }, @@ -75,17 +79,6 @@ Template.userFormsLayout.helpers({ const curLang = T9n.getLanguage() || 'en'; return t9nTag === curLang; }, -/* - isCas() { - return Meteor.settings.public && - Meteor.settings.public.cas && - Meteor.settings.public.cas.loginUrl; - }, - - casSignInLabel() { - return TAPi18n.__('casSignIn', {}, T9n.getLanguage() || 'en'); - }, -*/ }); Template.userFormsLayout.events({ @@ -94,55 +87,74 @@ Template.userFormsLayout.events({ T9n.setLanguage(i18nTagToT9n(i18nTag)); evt.preventDefault(); }, - 'click button#cas'() { + 'click #at-btn'(event, instance) { + if (FlowRouter.getRouteName() === 'atSignIn') { + authentication(event, instance); + } + }, +}); + +Template.defaultLayout.events({ + 'click .js-close-modal': () => { + Modal.close(); + }, +}); + +async function authentication(event, instance) { + const match = $('#at-field-username_and_email').val(); + const password = $('#at-field-password').val(); + + if (!match || !password) return; + + const result = await getAuthenticationMethod(instance.currentSetting.get(), match); + + if (result === 'password') return; + + // Stop submit #at-pwd-form + event.preventDefault(); + event.stopImmediatePropagation(); + + switch (result) { + case 'ldap': + Meteor.loginWithLDAP(match, password, function() { + FlowRouter.go('/'); + }); + break; + + case 'cas': Meteor.loginWithCas(function() { - if (FlowRouter.getRouteName() === 'atSignIn') { - FlowRouter.go('/'); - } + FlowRouter.go('/'); }); - }, - 'click #at-btn'(event) { - /* All authentication method can be managed/called here. - !! DON'T FORGET to correctly fill the fields of the user during its creation if necessary authenticationMethod : String !! - */ - const authenticationMethodSelected = $('.select-authentication').val(); - // Local account - if (authenticationMethodSelected === 'password') { - return; - } + break; - // Stop submit #at-pwd-form - event.preventDefault(); - event.stopImmediatePropagation(); + default: + break; + } +} - const email = $('#at-field-username_and_email').val(); - const password = $('#at-field-password').val(); +function getAuthenticationMethod({displayAuthenticationMethod, defaultAuthenticationMethod}, match) { + if (displayAuthenticationMethod) { + return $('.select-authentication').val(); + } + return getUserAuthenticationMethod(defaultAuthenticationMethod, match); +} - // Ldap account - if (authenticationMethodSelected === 'ldap') { - // Check if the user can use the ldap connection - Meteor.subscribe('user-authenticationMethod', email, { +function getUserAuthenticationMethod(defaultAuthenticationMethod, match) { + return new Promise((resolve) => { + try { + Meteor.subscribe('user-authenticationMethod', match, { 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(); + + const authenticationMethod = user + ? user.authenticationMethod + : defaultAuthenticationMethod; + + resolve(authenticationMethod); }, }); + } catch(error) { + resolve(defaultAuthenticationMethod); } - }, -}); - -Template.defaultLayout.events({ - 'click .js-close-modal': () => { - Modal.close(); - }, -}); + }); +} |