accounts.js 2.1 KB

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