accounts.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 passwordLoginDisabled = 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('isPasswordLoginDisabled', (_, result) => {
  17. if (result) {
  18. passwordLoginDisabled = true;
  19. //console.log('passwordLoginDisabled');
  20. //console.log(result);
  21. }
  22. });
  23. Meteor.call('getOauthServerUrl', (_, result) => {
  24. if (result) {
  25. oauthServerUrl = result;
  26. }
  27. });
  28. Meteor.call('getOauthDashboardUrl', (_, result) => {
  29. if (result) {
  30. oauthDashboardUrl = result;
  31. }
  32. });
  33. Meteor.call('isDisableRegistration', (_, result) => {
  34. if (result) {
  35. disableRegistration = true;
  36. //console.log('disableRegistration');
  37. //console.log(result);
  38. }
  39. });
  40. Meteor.call('isDisableForgotPassword', (_, result) => {
  41. if (result) {
  42. disableForgotPassword = true;
  43. //console.log('disableForgotPassword');
  44. //console.log(result);
  45. }
  46. });
  47. AccountsTemplates.addFields([
  48. {
  49. _id: 'username',
  50. type: 'text',
  51. displayName: 'username',
  52. required: true,
  53. minLength: 2,
  54. },
  55. emailField,
  56. passwordField,
  57. {
  58. _id: 'invitationcode',
  59. type: 'text',
  60. displayName: 'Invitation Code',
  61. required: false,
  62. minLength: 6,
  63. template: 'invitationCode',
  64. },
  65. ]);
  66. AccountsTemplates.configure({
  67. defaultLayout: 'userFormsLayout',
  68. defaultContentRegion: 'content',
  69. confirmPassword: true,
  70. enablePasswordChange: true,
  71. sendVerificationEmail: true,
  72. showForgotPasswordLink: !disableForgotPassword,
  73. forbidClientAccountCreation: disableRegistration,
  74. onLogoutHook() {
  75. // here comeslogic for redirect
  76. if(oidcRedirectionEnabled)
  77. {
  78. window.location = oauthServerUrl + oauthDashboardUrl;
  79. }
  80. else
  81. {
  82. const homePage = 'home';
  83. if (FlowRouter.getRouteName() === homePage) {
  84. FlowRouter.reload();
  85. } else {
  86. FlowRouter.go(homePage);
  87. }
  88. }
  89. },
  90. });
  91. if (!disableForgotPassword) {
  92. [
  93. 'forgotPwd',
  94. 'resetPwd',
  95. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  96. }
  97. if (!disableRegistration) {
  98. [
  99. 'signUp',
  100. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  101. }
  102. [
  103. 'signIn',
  104. 'enrollAccount',
  105. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  106. // We display the form to change the password in a popup window that already
  107. // have a title, so we unset the title automatically displayed by useraccounts.
  108. AccountsTemplates.configure({
  109. texts: {
  110. title: {
  111. changePwd: '',
  112. },
  113. },
  114. });
  115. AccountsTemplates.configureRoute('changePwd', {
  116. redirect() {
  117. // XXX We should emit a notification once we have a notification system.
  118. // Currently the user has no indication that his modification has been
  119. // applied.
  120. Popup.back();
  121. },
  122. });
  123. if (Meteor.isServer) {
  124. [
  125. 'resetPassword-subject',
  126. 'resetPassword-text',
  127. 'verifyEmail-subject',
  128. 'verifyEmail-text',
  129. 'enrollAccount-subject',
  130. 'enrollAccount-text',
  131. ].forEach(str => {
  132. const [templateName, field] = str.split('-');
  133. Accounts.emailTemplates[templateName][field] = (user, url) => {
  134. return TAPi18n.__(
  135. `email-${str}`,
  136. {
  137. url,
  138. user: user.getName(),
  139. siteName: Accounts.emailTemplates.siteName,
  140. },
  141. user.getLanguage(),
  142. );
  143. };
  144. });
  145. }