connectionMethod.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. Template.connectionMethod.onCreated(function() {
  2. this.authenticationMethods = new ReactiveVar([]);
  3. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  4. if (result) {
  5. // TODO : add a management of different languages
  6. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  7. this.authenticationMethods.set([
  8. { value: 'password' },
  9. // Gets only the authentication methods availables
  10. ...Object.entries(result)
  11. .filter(e => e[1])
  12. .map(e => ({ value: e[0] })),
  13. ]);
  14. }
  15. // If only the default authentication available, hides the select boxe
  16. const content = $('.at-form-authentication');
  17. // OAuth method is a separate button, so ignore it in the count
  18. const formAuthenticationMethods = this.authenticationMethods.get().filter((method) => method.value !== 'oauth2');
  19. if (formAuthenticationMethods > 1) {
  20. content.show();
  21. } else {
  22. content.hide();
  23. }
  24. });
  25. });
  26. Template.connectionMethod.onRendered(() => {
  27. // Moves the select boxe in the first place of the at-pwd-form div
  28. $('.at-form-authentication')
  29. .detach()
  30. .prependTo('.at-pwd-form');
  31. });
  32. Template.connectionMethod.helpers({
  33. authentications() {
  34. return Template.instance().authenticationMethods.get();
  35. },
  36. isSelected(match) {
  37. return Template.instance().data.authenticationMethod === match;
  38. },
  39. });