connectionMethod.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. Template.connectionMethod.onCreated(function() {
  2. this.authenticationMethods = new ReactiveVar([]);
  3. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  4. if (result) {
  5. // Only enabled auth methods without OAuth2/OpenID which is a separate button
  6. const tmp = Object.keys(result).filter((k) => result[k]).filter((k) => k !== 'oauth2');
  7. // TODO : add a management of different languages
  8. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  9. this.authenticationMethods.set([{ value: 'password' }].concat(tmp.map((k) => { return { value: k }; })));
  10. }
  11. // If only the default authentication available, hides the select boxe
  12. const content = $('.at-form-authentication');
  13. if (this.authenticationMethods.get().length > 1) {
  14. content.show();
  15. } else {
  16. content.hide();
  17. }
  18. });
  19. });
  20. Template.connectionMethod.onRendered(() => {
  21. // Moves the select boxe in the first place of the at-pwd-form div
  22. $('.at-form-authentication')
  23. .detach()
  24. .prependTo('.at-pwd-form');
  25. });
  26. Template.connectionMethod.helpers({
  27. authentications() {
  28. return Template.instance().authenticationMethods.get();
  29. },
  30. isSelected(match) {
  31. return Template.instance().data.authenticationMethod === match;
  32. },
  33. });