SHARE
TWEET

Untitled

a guest Aug 14th, 2019 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global.sess = null;
  2.  
  3.  
  4. app.post("/signin", function (req, res) {
  5.     sess = req.session;
  6.     var email = req.body.email;
  7.     var password = req.body.password;
  8.  
  9.     const userData = {
  10.       email: email.trim(),
  11.       password: password.trim()
  12.     };
  13.  
  14.       if(!req.body.email ) {
  15.               req.flash('error', 'Enter a Valid Email address');
  16.               return res.redirect('/signin');
  17.             }
  18.             if(!req.body.password) {
  19.               req.flash('error', 'Password should not be Empty.')
  20.               return res.redirect('/signin');
  21.             }
  22.  
  23.     // find a user by email address
  24.     User.findOne({ email: userData.email }, (err, user) => {
  25.       console.log ("user...", user);
  26.  
  27.       if (err) { throw err; }
  28.  
  29.       if (!user) {
  30.               req.flash('error', 'User details is not found for this email, please register....');
  31.               return res.redirect('/signin');
  32.  
  33.       }
  34.  
  35.       // check if a hashed user's password is equal to a value saved in the database
  36.        user.comparePassword(userData.password, (passwordErr, isMatch) => {
  37.          if (err) { throw err; }
  38.       if(user.status == 'Suspended') {
  39.                             req.flash('error', 'Your Account is Suspended. please contact the admin');
  40.                             return res.redirect('/signin');
  41.                           }
  42.  
  43.  
  44.       if(user.status != 'Active') {
  45.                             req.flash('error', 'Your Account is Not Verified. please Verify');
  46.                             return res.redirect('/signin');
  47.                           }
  48.  
  49.  
  50.  
  51.         if (!isMatch) {
  52.  
  53.               req.flash('error', 'Incorrect email or password, please try again..');
  54.               return res.redirect('/signin');
  55.  
  56.         } else {
  57.  
  58.  
  59.           sess.user = user;
  60.           req.flash('success', 'Login successful');
  61.           res.redirect("/eventica");
  62.         }
  63.       });
  64.     });
  65.   });
  66.  
  67.  
  68.  
  69. //In app.js
  70.  
  71. var express = require('express'),
  72.   app = module.exports = express();
  73. var session = require('express-session');
  74. app.use(session({ secret: 'ssshhhhh' }));
  75.  
  76. app.engine('.html', require('ejs').__express);
  77. app.use(express.static(__dirname + '/public'));
  78.  
  79. bodyParser = require('body-parser');
  80. app.use(bodyParser.urlencoded({ extended: false }))
  81. app.use(bodyParser.json())
  82. var flash = require('express-flash');
  83. app.use(flash());
  84.  
  85. app.set('view engine', 'html');
  86. app.set('views', __dirname + '/views');
  87.  
  88. global.sess=null;
  89.  
  90.  
  91.  
  92. app.get('/', function (req, res) {
  93.  
  94.  sess = req.session;
  95.  
  96.  
  97.   if (req.session.user) {
  98.  
  99.     res.render('eventica', {
  100.  
  101.     });
  102.   }
  103.   else {
  104.  
  105.     res.render('firsteventica', {
  106.  
  107.     });
  108.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top