accounts.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import { TAPi18n } from '/imports/i18n';
  2. const passwordField = AccountsTemplates.removeField('password');
  3. passwordField.autocomplete = 'current-password';
  4. const emailField = AccountsTemplates.removeField('email');
  5. let disableRegistration = false;
  6. let disableForgotPassword = false;
  7. let passwordLoginEnabled = false;
  8. let oidcRedirectionEnabled = false;
  9. let oauthServerUrl = "home";
  10. let oauthDashboardUrl = "";
  11. Meteor.call('isOidcRedirectionEnabled', (_, result) => {
  12. if(result)
  13. {
  14. oidcRedirectionEnabled = true;
  15. }
  16. });
  17. Meteor.call('isPasswordLoginEnabled', (_, result) => {
  18. if (result) {
  19. passwordLoginEnabled = true;
  20. }
  21. });
  22. Meteor.call('getOauthServerUrl', (_, result) => {
  23. if (result) {
  24. oauthServerUrl = result;
  25. }
  26. });
  27. Meteor.call('getOauthDashboardUrl', (_, result) => {
  28. if (result) {
  29. oauthDashboardUrl = result;
  30. }
  31. });
  32. Meteor.call('isDisableRegistration', (_, result) => {
  33. if (result) {
  34. disableRegistration = true;
  35. //console.log('disableRegistration');
  36. //console.log(result);
  37. }
  38. });
  39. Meteor.call('isDisableForgotPassword', (_, result) => {
  40. if (result) {
  41. disableForgotPassword = true;
  42. //console.log('disableForgotPassword');
  43. //console.log(result);
  44. }
  45. });
  46. AccountsTemplates.addFields([
  47. {
  48. _id: 'username',
  49. type: 'text',
  50. displayName: 'username',
  51. required: true,
  52. minLength: 2,
  53. autocomplete: 'username',
  54. },
  55. emailField,
  56. passwordField,
  57. {
  58. _id: 'password_again',
  59. type: 'password',
  60. displayName: 'Password (again)',
  61. required: true,
  62. minLength: 6,
  63. autocomplete: 'new-password',
  64. },
  65. {
  66. _id: 'invitationcode',
  67. type: 'text',
  68. displayName: 'Invitation Code',
  69. required: false,
  70. minLength: 6,
  71. template: 'invitationCode',
  72. },
  73. ]);
  74. AccountsTemplates.configure({
  75. defaultLayout: 'userFormsLayout',
  76. defaultContentRegion: 'content',
  77. confirmPassword: true,
  78. enablePasswordChange: true,
  79. sendVerificationEmail: true,
  80. showForgotPasswordLink: !disableForgotPassword,
  81. forbidClientAccountCreation: disableRegistration,
  82. onLogoutHook() {
  83. // here comeslogic for redirect
  84. if(oidcRedirectionEnabled)
  85. {
  86. window.location = oauthServerUrl + oauthDashboardUrl;
  87. }
  88. else
  89. {
  90. const homePage = 'home';
  91. if (FlowRouter.getRouteName() === homePage) {
  92. FlowRouter.reload();
  93. } else {
  94. FlowRouter.go(homePage);
  95. }
  96. }
  97. },
  98. });
  99. if (!disableForgotPassword) {
  100. [
  101. 'forgotPwd',
  102. 'resetPwd',
  103. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  104. }
  105. if (!disableRegistration) {
  106. [
  107. 'signUp',
  108. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  109. }
  110. [
  111. 'signIn',
  112. 'enrollAccount',
  113. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  114. // We display the form to change the password in a popup window that already
  115. // have a title, so we unset the title automatically displayed by useraccounts.
  116. AccountsTemplates.configure({
  117. texts: {
  118. title: {
  119. changePwd: '',
  120. },
  121. },
  122. });
  123. AccountsTemplates.configureRoute('changePwd', {
  124. redirect() {
  125. // We should go back with the popup but we don't since user feedback about the change is within the popup only.
  126. // Once we have a global feedback popup mechanism we can use that here and close with the following:
  127. // Popup.back();
  128. },
  129. });
  130. if (Meteor.isServer) {
  131. [
  132. 'resetPassword-subject',
  133. 'resetPassword-text',
  134. 'verifyEmail-subject',
  135. 'verifyEmail-text',
  136. 'enrollAccount-subject',
  137. 'enrollAccount-text',
  138. ].forEach(str => {
  139. const [templateName, field] = str.split('-');
  140. Accounts.emailTemplates[templateName][field] = (user, url) => {
  141. return TAPi18n.__(
  142. `email-${str}`,
  143. {
  144. url,
  145. user: user.getName(),
  146. siteName: Accounts.emailTemplates.siteName,
  147. },
  148. user.getLanguage(),
  149. );
  150. };
  151. });
  152. }