accounts.js 3.6 KB

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