accounts.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. AccountsTemplates.configure({
  11. defaultLayout: 'userFormsLayout',
  12. defaultContentRegion: 'content',
  13. confirmPassword: false,
  14. enablePasswordChange: true,
  15. sendVerificationEmail: true,
  16. showForgotPasswordLink: true,
  17. onLogoutHook() {
  18. const homePage = 'home';
  19. if (FlowRouter.getRouteName() === homePage) {
  20. FlowRouter.reload();
  21. } else {
  22. FlowRouter.go(homePage);
  23. }
  24. },
  25. });
  26. ['signIn', 'signUp', 'resetPwd', 'forgotPwd', 'enrollAccount'].forEach(
  27. (routeName) => AccountsTemplates.configureRoute(routeName));
  28. // We display the form to change the password in a popup window that already
  29. // have a title, so we unset the title automatically displayed by useraccounts.
  30. AccountsTemplates.configure({
  31. texts: {
  32. title: {
  33. changePwd: '',
  34. },
  35. },
  36. });
  37. AccountsTemplates.configureRoute('changePwd', {
  38. redirect() {
  39. // XXX We should emit a notification once we have a notification system.
  40. // Currently the user has no indication that his modification has been
  41. // applied.
  42. Popup.back();
  43. },
  44. });
  45. if (Meteor.isServer) {
  46. if (process.env.MAIL_FROM) {
  47. Accounts.emailTemplates.from = process.env.MAIL_FROM;
  48. }
  49. ['resetPassword-subject', 'resetPassword-text', 'verifyEmail-subject', 'verifyEmail-text', 'enrollAccount-subject', 'enrollAccount-text'].forEach((str) => {
  50. const [templateName, field] = str.split('-');
  51. Accounts.emailTemplates[templateName][field] = (user, url) => {
  52. return TAPi18n.__(`email-${str}`, {
  53. url,
  54. user: user.getName(),
  55. siteName: Accounts.emailTemplates.siteName,
  56. }, user.getLanguage());
  57. };
  58. });
  59. }