123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- 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;
- };
- let alreadyCheck = 1;
- let isCheckDone = false;
- const validator = {
- set(obj, prop, value) {
- 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;
- },
- };
- // let isSettingDatabaseFctCallDone = false;
- Template.userFormsLayout.onCreated(function() {
- const templateInstance = this;
- templateInstance.currentSetting = new ReactiveVar();
- templateInstance.isLoading = new ReactiveVar(false);
- Meteor.subscribe('setting', {
- onReady() {
- templateInstance.currentSetting.set(Settings.findOne());
- let currSetting = templateInstance.currentSetting.curValue;
- let oidcBtnElt = $("#at-oidc");
- if(currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined){
- let htmlvalue = "<i class='fa fa-oidc'></i>" + currSetting.oidcBtnText;
- oidcBtnElt.html(htmlvalue);
- }
- // isSettingDatabaseFctCallDone = true;
- if(currSetting && currSetting !== undefined && currSetting.customLoginLogoImageUrl !== undefined)
- document.getElementById("isSettingDatabaseCallDone").style.display = 'none';
- else
- document.getElementById("isSettingDatabaseCallDone").style.display = 'block';
- return this.stop();
- },
- });
- Meteor.call('isPasswordLoginDisabled', (_, result) => {
- if (result) {
- $('.at-pwd-form').hide();
- }
- });
- });
- Template.userFormsLayout.onRendered(() => {
- AccountsTemplates.state.form.keys = new Proxy(
- AccountsTemplates.state.form.keys,
- validator,
- );
- const i18nTag = navigator.language;
- if (i18nTag) {
- T9n.setLanguage(i18nTagToT9n(i18nTag));
- }
- EscapeActions.executeAll();
- });
- Template.userFormsLayout.helpers({
- currentSetting() {
- return Template.instance().currentSetting.get();
- },
- // isSettingDatabaseCallDone(){
- // return isSettingDatabaseFctCallDone;
- // },
- isLoading() {
- return Template.instance().isLoading.get();
- },
- afterBodyStart() {
- return currentSetting.customHTMLafterBodyStart;
- },
- beforeBodyEnd() {
- return currentSetting.customHTMLbeforeBodyEnd;
- },
- languages() {
- return _.map(TAPi18n.getLanguages(), (lang, code) => {
- const tag = code;
- let name = lang.name;
- if (lang.name === 'br') {
- name = 'Brezhoneg';
- } else if (lang.name === 'ar-EG') {
- // ar-EG = Arabic (Egypt), simply Masri (مَصرى, [ˈmɑsˤɾi], Egyptian, Masr refers to Cairo)
- name = 'مَصرى';
- } else if (lang.name === 'de-CH') {
- name = 'Deutsch (Schweiz)';
- } else if (lang.name === 'fa-IR') {
- // fa-IR = Persian (Iran)
- name = 'فارسی/پارسی (ایران)';
- } else if (lang.name === 'fr-BE') {
- name = 'Français (Belgique)';
- } else if (lang.name === 'fr-CA') {
- name = 'Français (Canada)';
- } else if (lang.name === 'fr-CH') {
- name = 'Français (Schweiz)';
- } else if (lang.name === 'ig') {
- name = 'Igbo';
- } else if (lang.name === 'lv') {
- name = 'Latviešu';
- } else if (lang.name === 'latviešu valoda') {
- name = 'Latviešu';
- } else if (lang.name === 'en-IT') {
- name = 'English (Italy)';
- } else if (lang.name === 'Español') {
- name = 'español';
- } else if (lang.name === 'es_419') {
- name = 'español de América Latina';
- } else if (lang.name === 'es-419') {
- name = 'español de América Latina';
- } else if (lang.name === 'Español de América Latina') {
- name = 'español de América Latina';
- } else if (lang.name === 'es-LA') {
- name = 'español de América Latina';
- } else if (lang.name === 'Español de Argentina') {
- name = 'español de Argentina';
- } else if (lang.name === 'Español de Chile') {
- name = 'español de Chile';
- } else if (lang.name === 'Español de Colombia') {
- name = 'español de Colombia';
- } else if (lang.name === 'Español de México') {
- name = 'español de México';
- } else if (lang.name === 'es-PY') {
- name = 'español de Paraguayo';
- } else if (lang.name === 'Español de Paraguayo') {
- name = 'español de Paraguayo';
- } else if (lang.name === 'Español de Perú') {
- name = 'español de Perú';
- } else if (lang.name === 'Español de Puerto Rico') {
- name = 'español de Puerto Rico';
- } else if (lang.name === 'oc') {
- name = 'Occitan';
- } else if (lang.name === 'st') {
- name = 'Sãotomense';
- } else if (lang.name === '繁体中文(台湾)') {
- name = '繁體中文(台灣)';
- }
- 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;
- },
- });
- Template.userFormsLayout.events({
- 'change .js-userform-set-language'(event) {
- const i18nTag = $(event.currentTarget).val();
- T9n.setLanguage(i18nTagToT9n(i18nTag));
- event.preventDefault();
- },
- 'click #at-btn'(event, templateInstance) {
- if (FlowRouter.getRouteName() === 'atSignIn') {
- templateInstance.isLoading.set(true);
- authentication(event, templateInstance).then(() => {
- templateInstance.isLoading.set(false);
- });
- }
- },
- 'DOMSubtreeModified #at-oidc'(event){
- if(alreadyCheck <= 2){
- let currSetting = Settings.findOne();
- let oidcBtnElt = $("#at-oidc");
- if(currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined){
- let htmlvalue = "<i class='fa fa-oidc'></i>" + currSetting.oidcBtnText;
- if(alreadyCheck == 1){
- alreadyCheck++;
- oidcBtnElt.html("");
- }
- else{
- alreadyCheck++;
- oidcBtnElt.html(htmlvalue);
- }
- }
- }
- else{
- alreadyCheck = 1;
- }
- },
- 'DOMSubtreeModified .at-form'(event){
- if(alreadyCheck <= 2 && !isCheckDone){
- if(document.getElementById("at-oidc") != null){
- let currSetting = Settings.findOne();
- let oidcBtnElt = $("#at-oidc");
- if(currSetting && currSetting !== undefined && currSetting.oidcBtnText !== undefined && oidcBtnElt != null && oidcBtnElt != undefined){
- let htmlvalue = "<i class='fa fa-oidc'></i>" + currSetting.oidcBtnText;
- if(alreadyCheck == 1){
- alreadyCheck++;
- oidcBtnElt.html("");
- }
- else{
- alreadyCheck++;
- isCheckDone = true;
- oidcBtnElt.html(htmlvalue);
- }
- }
- }
- }
- else{
- alreadyCheck = 1;
- }
- },
- });
- Template.defaultLayout.events({
- 'click .js-close-modal': () => {
- Modal.close();
- },
- });
- async function authentication(event, templateInstance) {
- const match = $('#at-field-username_and_email').val();
- const password = $('#at-field-password').val();
- if (!match || !password) return undefined;
- const result = await getAuthenticationMethod(
- templateInstance.currentSetting.get(),
- match,
- );
- if (result === 'password') return undefined;
- // Stop submit #at-pwd-form
- event.preventDefault();
- event.stopImmediatePropagation();
- switch (result) {
- case 'ldap':
- return new Promise(resolve => {
- Meteor.loginWithLDAP(match, password, function() {
- resolve(FlowRouter.go('/'));
- });
- });
- case 'saml':
- return new Promise(resolve => {
- const provider = Meteor.settings.public.SAML_PROVIDER;
- Meteor.loginWithSaml(
- {
- provider,
- },
- function() {
- resolve(FlowRouter.go('/'));
- },
- );
- });
- case 'cas':
- return new Promise(resolve => {
- Meteor.loginWithCas(match, password, function() {
- resolve(FlowRouter.go('/'));
- });
- });
- default:
- return undefined;
- }
- }
- function getAuthenticationMethod(
- { displayAuthenticationMethod, defaultAuthenticationMethod },
- match,
- ) {
- if (displayAuthenticationMethod) {
- return $('.select-authentication').val();
- }
- return getUserAuthenticationMethod(defaultAuthenticationMethod, match);
- }
- function getUserAuthenticationMethod(defaultAuthenticationMethod, match) {
- return new Promise(resolve => {
- try {
- Meteor.subscribe('user-authenticationMethod', match, {
- onReady() {
- const user = Users.findOne();
- const authenticationMethod = user
- ? user.authenticationMethod
- : defaultAuthenticationMethod;
- resolve(authenticationMethod);
- },
- });
- } catch (error) {
- resolve(defaultAuthenticationMethod);
- }
- });
- }
|