layouts.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. BlazeLayout.setRoot('body');
  2. const i18nTagToT9n = (i18nTag) => {
  3. // t9n/i18n tags are same now, see: https://github.com/softwarerero/meteor-accounts-t9n/pull/129
  4. // but we keep this conversion function here, to be aware that that they are different system.
  5. return i18nTag;
  6. };
  7. const validator = {
  8. set(obj, prop, value) {
  9. if (prop === 'state' && value !== 'signIn') {
  10. $('.at-form-authentication').hide();
  11. } else if (prop === 'state' && value === 'signIn') {
  12. $('.at-form-authentication').show();
  13. }
  14. // The default behavior to store the value
  15. obj[prop] = value;
  16. // Indicate success
  17. return true;
  18. },
  19. };
  20. Template.userFormsLayout.onCreated(() => {
  21. Meteor.subscribe('setting');
  22. });
  23. Template.userFormsLayout.onRendered(() => {
  24. AccountsTemplates.state.form.keys = new Proxy(AccountsTemplates.state.form.keys, validator);
  25. const i18nTag = navigator.language;
  26. if (i18nTag) {
  27. T9n.setLanguage(i18nTagToT9n(i18nTag));
  28. }
  29. EscapeActions.executeAll();
  30. });
  31. Template.userFormsLayout.helpers({
  32. currentSetting() {
  33. return Settings.findOne();
  34. },
  35. afterBodyStart() {
  36. return currentSetting.customHTMLafterBodyStart;
  37. },
  38. beforeBodyEnd() {
  39. return currentSetting.customHTMLbeforeBodyEnd;
  40. },
  41. languages() {
  42. return _.map(TAPi18n.getLanguages(), (lang, code) => {
  43. const tag = code;
  44. let name = lang.name;
  45. if (lang.name === 'br') {
  46. name = 'Brezhoneg';
  47. } else if (lang.name === 'ig') {
  48. name = 'Igbo';
  49. }
  50. return { tag, name };
  51. }).sort(function(a, b) {
  52. if (a.name === b.name) {
  53. return 0;
  54. } else {
  55. return a.name > b.name ? 1 : -1;
  56. }
  57. });
  58. },
  59. isCurrentLanguage() {
  60. const t9nTag = i18nTagToT9n(this.tag);
  61. const curLang = T9n.getLanguage() || 'en';
  62. return t9nTag === curLang;
  63. },
  64. /*
  65. isCas() {
  66. return Meteor.settings.public &&
  67. Meteor.settings.public.cas &&
  68. Meteor.settings.public.cas.loginUrl;
  69. },
  70. casSignInLabel() {
  71. return TAPi18n.__('casSignIn', {}, T9n.getLanguage() || 'en');
  72. },
  73. */
  74. });
  75. Template.userFormsLayout.events({
  76. 'change .js-userform-set-language'(evt) {
  77. const i18nTag = $(evt.currentTarget).val();
  78. T9n.setLanguage(i18nTagToT9n(i18nTag));
  79. evt.preventDefault();
  80. },
  81. 'click button#cas'() {
  82. Meteor.loginWithCas(function() {
  83. if (FlowRouter.getRouteName() === 'atSignIn') {
  84. FlowRouter.go('/');
  85. }
  86. });
  87. },
  88. 'click #at-btn'(event) {
  89. /* All authentication method can be managed/called here.
  90. !! DON'T FORGET to correctly fill the fields of the user during its creation if necessary authenticationMethod : String !!
  91. */
  92. const authenticationMethodSelected = $('.select-authentication').val();
  93. // Local account
  94. if (authenticationMethodSelected === 'password') {
  95. return;
  96. }
  97. // Stop submit #at-pwd-form
  98. event.preventDefault();
  99. event.stopImmediatePropagation();
  100. const email = $('#at-field-username_and_email').val();
  101. const password = $('#at-field-password').val();
  102. // Ldap account
  103. if (authenticationMethodSelected === 'ldap') {
  104. // Check if the user can use the ldap connection
  105. Meteor.subscribe('user-authenticationMethod', email, {
  106. onReady() {
  107. const user = Users.findOne();
  108. if (user === undefined || user.authenticationMethod === 'ldap') {
  109. // Use the ldap connection package
  110. Meteor.loginWithLDAP(email, password, function(error) {
  111. if (!error) {
  112. // Connection
  113. return FlowRouter.go('/');
  114. }
  115. return error;
  116. });
  117. }
  118. return this.stop();
  119. },
  120. });
  121. }
  122. },
  123. });
  124. Template.defaultLayout.events({
  125. 'click .js-close-modal': () => {
  126. Modal.close();
  127. },
  128. });