view-new-password.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. module.exports = {
  2. friendlyName: 'View new password',
  3. description: 'Display "New password" page.',
  4. inputs: {
  5. token: {
  6. description: 'The password reset token from the email.',
  7. example: '4-32fad81jdaf$329'
  8. }
  9. },
  10. exits: {
  11. success: {
  12. viewTemplatePath: 'pages/entrance/new-password'
  13. },
  14. invalidOrExpiredToken: {
  15. responseType: 'expired',
  16. description: 'The provided token is expired, invalid, or has already been used.',
  17. }
  18. },
  19. fn: async function (inputs, exits) {
  20. // If password reset token is missing, display an error page explaining that the link is bad.
  21. if (!inputs.token) {
  22. sails.log.warn('Attempting to view new password (recovery) page, but no reset password token included in request! Displaying error page...');
  23. throw 'invalidOrExpiredToken';
  24. }//•
  25. // Look up the user with this reset token.
  26. var userRecord = await User.findOne({ passwordResetToken: inputs.token });
  27. // If no such user exists, or their token is expired, display an error page explaining that the link is bad.
  28. if (!userRecord || userRecord.passwordResetTokenExpiresAt <= Date.now()) {
  29. throw 'invalidOrExpiredToken';
  30. }
  31. // Grab token and include it in view locals
  32. return exits.success({
  33. token: inputs.token
  34. });
  35. }
  36. };