Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const userQueries = require("../db/queries.users.js");
- const passport = require("passport");
- const sgMail = require('@sendgrid/mail');
- sgMail.setApiKey(process.env.SENDGRID_API_KEY);
- module.exports = {
- signUp(req, res, next){
- res.render("users/signup");
- },
- create(req, res, next){
- let newUser = {
- email: req.body.email,
- password: req.body.password,
- passwordConfirmation: req.body.passwordConfirmation
- };
- userQueries.createUser(newUser, (err, user) => {
- if(err){
- req.flash("error", err);
- res.redirect("/users/signup");
- } else {
- const msg = {
- to: req.body.email,
- from: 'welcome@blocipedia.com',
- subject: 'Welcome to Blocipedia!',
- text: 'Get ready to learn and collaborate',
- html: 'Get ready to learn and collaborate',
- };
- sgMail.send(msg);
- passport.authenticate("local")(req, res, () => {
- req.flash("notice", "You've successfully signed in!");
- res.redirect("/");
- })
- }
- });
- const msg = {
- to: req.body.email,
- from: 'welcome@blocipedia.com',
- subject: 'Welcome to Blocipedia!',
- text: 'Get ready to learn and collaborate',
- html: 'Get ready to learn and collaborate',
- };
- sgMail.send(msg);
- },
- signInForm(req, res, next){
- res.render("users/signin");
- },
- signIn(req, res, next){
- passport.authenticate("local")(req, res, function () {
- if(!req.user){
- req.flash("notice", "Sign in failed. Please try again.")
- res.redirect("/users/signin");
- } else {
- req.flash("notice", "You've successfully signed in!");
- res.redirect("/");
- }
- })
- },
- signOut(req, res, next){
- req.logout();
- req.flash("notice", "You've successfully signed out!");
- res.redirect("/");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement