accounts.js 2.9 KB

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