connectionMethod.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. if (this.authenticationMethods.get().some((method) => method.value === 'oauth2')) {
  25. $('.at-oauth').show();
  26. }
  27. Meteor.call('isPasswordLoginEnabled', (_, result) => {
  28. if (result) {
  29. $('.at-pwd-form').show();
  30. }
  31. if (result && this.authenticationMethods.get().length > 1) {
  32. $('.at-sep').show();
  33. }
  34. });
  35. });
  36. });
  37. Template.connectionMethod.onRendered(() => {
  38. // Moves the select boxe in the first place of the at-pwd-form div
  39. $('.at-form-authentication')
  40. .detach()
  41. .prependTo('.at-pwd-form');
  42. });
  43. Template.connectionMethod.helpers({
  44. authentications() {
  45. return Template.instance().authenticationMethods.get();
  46. },
  47. isSelected(match) {
  48. return Template.instance().data.authenticationMethod === match;
  49. },
  50. });