layouts.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.onRendered(() => {
  21. AccountsTemplates.state.form.keys = new Proxy(AccountsTemplates.state.form.keys, validator);
  22. const i18nTag = navigator.language;
  23. if (i18nTag) {
  24. T9n.setLanguage(i18nTagToT9n(i18nTag));
  25. }
  26. EscapeActions.executeAll();
  27. });
  28. Template.userFormsLayout.helpers({
  29. languages() {
  30. return _.map(TAPi18n.getLanguages(), (lang, code) => {
  31. const tag = code;
  32. let name = lang.name;
  33. if (lang.name === 'br') {
  34. name = 'Brezhoneg';
  35. } else if (lang.name === 'ig') {
  36. name = 'Igbo';
  37. }
  38. return { tag, name };
  39. }).sort(function(a, b) {
  40. if (a.name === b.name) {
  41. return 0;
  42. } else {
  43. return a.name > b.name ? 1 : -1;
  44. }
  45. });
  46. },
  47. isCurrentLanguage() {
  48. const t9nTag = i18nTagToT9n(this.tag);
  49. const curLang = T9n.getLanguage() || 'en';
  50. return t9nTag === curLang;
  51. },
  52. /*
  53. isCas() {
  54. return Meteor.settings.public &&
  55. Meteor.settings.public.cas &&
  56. Meteor.settings.public.cas.loginUrl;
  57. },
  58. casSignInLabel() {
  59. return TAPi18n.__('casSignIn', {}, T9n.getLanguage() || 'en');
  60. },
  61. */
  62. });
  63. Template.userFormsLayout.events({
  64. 'change .js-userform-set-language'(evt) {
  65. const i18nTag = $(evt.currentTarget).val();
  66. T9n.setLanguage(i18nTagToT9n(i18nTag));
  67. evt.preventDefault();
  68. },
  69. 'click button#cas'() {
  70. Meteor.loginWithCas(function() {
  71. if (FlowRouter.getRouteName() === 'atSignIn') {
  72. FlowRouter.go('/');
  73. }
  74. });
  75. },
  76. 'click #at-btn'(event) {
  77. /* All authentication method can be managed/called here.
  78. !! DON'T FORGET to correctly fill the fields of the user during its creation if necessary authenticationMethod : String !!
  79. */
  80. const authenticationMethodSelected = $('.select-authentication').val();
  81. // Local account
  82. if (authenticationMethodSelected === 'password') {
  83. return;
  84. }
  85. // Stop submit #at-pwd-form
  86. event.preventDefault();
  87. event.stopImmediatePropagation();
  88. const email = $('#at-field-username_and_email').val();
  89. const password = $('#at-field-password').val();
  90. // Ldap account
  91. if (authenticationMethodSelected === 'ldap') {
  92. // Check if the user can use the ldap connection
  93. Meteor.subscribe('user-authenticationMethod', email, {
  94. onReady() {
  95. const user = Users.findOne();
  96. if (user === undefined || user.authenticationMethod === 'ldap') {
  97. // Use the ldap connection package
  98. Meteor.loginWithLDAP(email, password, function(error) {
  99. if (!error) {
  100. // Connection
  101. return FlowRouter.go('/');
  102. }
  103. return error;
  104. });
  105. }
  106. return this.stop();
  107. },
  108. });
  109. }
  110. },
  111. });
  112. Template.defaultLayout.events({
  113. 'click .js-close-modal': () => {
  114. Modal.close();
  115. },
  116. });