accounts.js 2.7 KB

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