Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. const userQueries = require("../db/queries.users.js");
  2. const passport = require("passport");
  3. const sgMail = require('@sendgrid/mail');
  4.  
  5. sgMail.setApiKey(process.env.SENDGRID_API_KEY);
  6.  
  7. module.exports = {
  8. signUp(req, res, next){
  9. res.render("users/signup");
  10. },
  11.  
  12. create(req, res, next){
  13. let newUser = {
  14. email: req.body.email,
  15. password: req.body.password,
  16. passwordConfirmation: req.body.passwordConfirmation
  17. };
  18. userQueries.createUser(newUser, (err, user) => {
  19. if(err){
  20. req.flash("error", err);
  21. res.redirect("/users/signup");
  22. } else {
  23. passport.authenticate("local")(req, res, () => {
  24. req.flash("notice", "You've successfully signed in!");
  25. res.redirect("/");
  26. })
  27. }
  28. });
  29. },
  30.  
  31. signInForm(req, res, next){
  32. res.render("users/signin");
  33. },
  34.  
  35. signIn(req, res, next){
  36. passport.authenticate("local")(req, res, function () {
  37. if(!req.user){
  38. req.flash("notice", "Sign in failed. Please try again.")
  39. res.redirect("/users/signin");
  40. } else {
  41. req.flash("notice", "You've successfully signed in!");
  42. res.redirect("/");
  43. }
  44. })
  45. },
  46.  
  47. signOut(req, res, next){
  48. req.logout();
  49. req.flash("notice", "You've successfully signed out!");
  50. res.redirect("/");
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement