accounts.js 3.0 KB

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