accounts.js 2.0 KB

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