accounts.js 2.0 KB

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