accounts.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. },
  53. emailField,
  54. passwordField,
  55. {
  56. _id: 'invitationcode',
  57. type: 'text',
  58. displayName: 'Invitation Code',
  59. required: false,
  60. minLength: 6,
  61. template: 'invitationCode',
  62. },
  63. ]);
  64. AccountsTemplates.configure({
  65. defaultLayout: 'userFormsLayout',
  66. defaultContentRegion: 'content',
  67. confirmPassword: true,
  68. enablePasswordChange: true,
  69. sendVerificationEmail: true,
  70. showForgotPasswordLink: !disableForgotPassword,
  71. forbidClientAccountCreation: disableRegistration,
  72. onLogoutHook() {
  73. // here comeslogic for redirect
  74. if(oidcRedirectionEnabled)
  75. {
  76. window.location = oauthServerUrl + oauthDashboardUrl;
  77. }
  78. else
  79. {
  80. const homePage = 'home';
  81. if (FlowRouter.getRouteName() === homePage) {
  82. FlowRouter.reload();
  83. } else {
  84. FlowRouter.go(homePage);
  85. }
  86. }
  87. },
  88. });
  89. if (!disableForgotPassword) {
  90. [
  91. 'forgotPwd',
  92. 'resetPwd',
  93. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  94. }
  95. if (!disableRegistration) {
  96. [
  97. 'signUp',
  98. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  99. }
  100. [
  101. 'signIn',
  102. 'enrollAccount',
  103. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  104. // We display the form to change the password in a popup window that already
  105. // have a title, so we unset the title automatically displayed by useraccounts.
  106. AccountsTemplates.configure({
  107. texts: {
  108. title: {
  109. changePwd: '',
  110. },
  111. },
  112. });
  113. AccountsTemplates.configureRoute('changePwd', {
  114. redirect() {
  115. // We should go back with the popup but we don't since user feedback about the change is within the popup only.
  116. // Once we have a global feedback popup mechanism we can use that here and close with the following:
  117. // Popup.back();
  118. },
  119. });
  120. if (Meteor.isServer) {
  121. [
  122. 'resetPassword-subject',
  123. 'resetPassword-text',
  124. 'verifyEmail-subject',
  125. 'verifyEmail-text',
  126. 'enrollAccount-subject',
  127. 'enrollAccount-text',
  128. ].forEach(str => {
  129. const [templateName, field] = str.split('-');
  130. Accounts.emailTemplates[templateName][field] = (user, url) => {
  131. return TAPi18n.__(
  132. `email-${str}`,
  133. {
  134. url,
  135. user: user.getName(),
  136. siteName: Accounts.emailTemplates.siteName,
  137. },
  138. user.getLanguage(),
  139. );
  140. };
  141. });
  142. }