Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. router.post("/changeForgottenPassword", requireSubdomain, async({
  2. body,
  3. instance,
  4. hostname
  5. }, res) => {
  6. try {
  7. const email = body.email;
  8. if (!email) {
  9. throw new Error("Email is not provided");
  10. }
  11. const user = await User.findOne({
  12. instance: instance._id,
  13. email
  14. });
  15. if (!user) {
  16. throw new Error("User with such email does not exist");
  17. }
  18. var token = randtoken.generate(16);
  19. const passwordRequest = new PasswordRequest({
  20. token,
  21. instance: instance._id,
  22. userID: user._id
  23. });
  24. await passwordRequest.save();
  25. await sendPasswordRequestEmail(email, instance.name, token, hostname);
  26. return res.status(200).end();
  27. } catch (err) {
  28. res.status(400).json({
  29. error: err.message
  30. });
  31. }
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement