accounts.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. [
  39. 'signIn',
  40. 'signUp',
  41. 'resetPwd',
  42. 'forgotPwd',
  43. 'enrollAccount',
  44. ].forEach(routeName => AccountsTemplates.configureRoute(routeName));
  45. // We display the form to change the password in a popup window that already
  46. // have a title, so we unset the title automatically displayed by useraccounts.
  47. AccountsTemplates.configure({
  48. texts: {
  49. title: {
  50. changePwd: '',
  51. },
  52. },
  53. });
  54. AccountsTemplates.configureRoute('changePwd', {
  55. redirect() {
  56. // XXX We should emit a notification once we have a notification system.
  57. // Currently the user has no indication that his modification has been
  58. // applied.
  59. Popup.back();
  60. },
  61. });
  62. if (Meteor.isServer) {
  63. [
  64. 'resetPassword-subject',
  65. 'resetPassword-text',
  66. 'verifyEmail-subject',
  67. 'verifyEmail-text',
  68. 'enrollAccount-subject',
  69. 'enrollAccount-text',
  70. ].forEach(str => {
  71. const [templateName, field] = str.split('-');
  72. Accounts.emailTemplates[templateName][field] = (user, url) => {
  73. return TAPi18n.__(
  74. `email-${str}`,
  75. {
  76. url,
  77. user: user.getName(),
  78. siteName: Accounts.emailTemplates.siteName,
  79. },
  80. user.getLanguage(),
  81. );
  82. };
  83. });
  84. }