accounts.js 1.9 KB

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