wekan/client/components/main/layouts.js

137 lines
3.6 KiB
JavaScript
Raw Normal View History

BlazeLayout.setRoot('body');
const i18nTagToT9n = (i18nTag) => {
// t9n/i18n tags are same now, see: https://github.com/softwarerero/meteor-accounts-t9n/pull/129
// but we keep this conversion function here, to be aware that that they are different system.
return i18nTag;
};
Template.userFormsLayout.onCreated(() => {
Meteor.subscribe('setting');
Meteor.call('getDefaultAuthenticationMethod', (error, result) => {
this.data.defaultAuthenticationMethod = new ReactiveVar(error ? undefined : result);
});
});
Template.userFormsLayout.onRendered(() => {
const i18nTag = navigator.language;
if (i18nTag) {
T9n.setLanguage(i18nTagToT9n(i18nTag));
}
EscapeActions.executeAll();
});
Template.userFormsLayout.helpers({
currentSetting() {
return Settings.findOne();
},
languages() {
return _.map(TAPi18n.getLanguages(), (lang, code) => {
const tag = code;
let name = lang.name;
if (lang.name === 'br') {
name = 'Brezhoneg';
} else if (lang.name === 'ig') {
name = 'Igbo';
}
return { tag, name };
}).sort(function(a, b) {
if (a.name === b.name) {
return 0;
} else {
return a.name > b.name ? 1 : -1;
}
});
},
isCurrentLanguage() {
const t9nTag = i18nTagToT9n(this.tag);
const curLang = T9n.getLanguage() || 'en';
return t9nTag === curLang;
},
/*
2018-07-03 15:55:19 +02:00
isCas() {
return Meteor.settings.public &&
Meteor.settings.public.cas &&
2018-07-03 16:08:18 +02:00
Meteor.settings.public.cas.loginUrl;
2018-07-03 15:55:19 +02:00
},
casSignInLabel() {
return TAPi18n.__('casSignIn', {}, T9n.getLanguage() || 'en');
},
*/
});
Template.userFormsLayout.events({
'change .js-userform-set-language'(evt) {
const i18nTag = $(evt.currentTarget).val();
T9n.setLanguage(i18nTagToT9n(i18nTag));
evt.preventDefault();
},
2018-07-03 15:55:19 +02:00
'click button#cas'() {
Meteor.loginWithCas(function() {
if (FlowRouter.getRouteName() === 'atSignIn') {
2018-07-03 15:55:19 +02:00
FlowRouter.go('/');
}
});
},
'click #at-btn'(event, instance) {
2018-10-09 21:16:47 +03:00
/* 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 email = $('#at-field-username_and_email').val();
const password = $('#at-field-password').val();
if (FlowRouter.getRouteName() !== 'atSignIn' || password === '') {
return;
}
2018-11-09 17:46:02 +01:00
// Stop submit #at-pwd-form
event.preventDefault();
event.stopImmediatePropagation();
Meteor.subscribe('user-authenticationMethod', email, {
onReady() {
return authentication.call(this, instance, email, password);
},
});
},
});
Template.defaultLayout.events({
'click .js-close-modal': () => {
Modal.close();
},
});
function authentication(instance, email, password) {
let user = Users.findOne();
// Authentication with password
if (user && user.authenticationMethod === 'password') {
$('#at-pwd-form').submit();
// Meteor.call('logoutWithTimer', user._id, () => {});
return this.stop();
}
// If user doesn't exist, uses the default authentication method if it defined
if (user === undefined) {
user = {
'authenticationMethod': instance.data.defaultAuthenticationMethod.get(),
};
}
// Authentication with LDAP
if (user.authenticationMethod === 'ldap') {
// Use the ldap connection package
Meteor.loginWithLDAP(email, password, function(error) {
if (!error) {
// Meteor.call('logoutWithTimer', Users.findOne()._id, () => {});
return FlowRouter.go('/');
}
return error;
});
}
return this.stop();
}