accounts.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { TAPi18n } from '/imports/i18n';
  2. import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
  3. const passwordField = AccountsTemplates.removeField('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. },
  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. }