SHARE
TWEET

Untitled

a guest Apr 2nd, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //     Users      //
  2.  
  3. let users = []
  4. let persistedUser = {}
  5.  
  6. app.post('/register', (req,res) => {
  7.   let username = req.body.username
  8.   let password = req.body.password
  9.  
  10.   let user = {username: username, password: password, userTrips: []}
  11.   users.push(user)
  12.   console.log(users)
  13.  
  14.   res.render('home', {messageA: 'Thank you for registering! Please login below.'})
  15. })
  16.  
  17. app.post('/login', (req,res) => {
  18.   let username = req.body.username
  19.   let password = req.body.password
  20.  
  21.   let user = {username: username, password: password, userTrips: []}
  22.  
  23.     persistedUser = users.find((user) => {
  24.     return user.username == username && user.password == password
  25.   })
  26.  
  27.   if(persistedUser) {
  28.     if(req.session) {
  29.       req.session.username = persistedUser.username
  30.       res.redirect('/addtrip')
  31.     }
  32.   } else {
  33.     res.render('home', {message: 'The User Name or Password is incorrect. Please try again!'})
  34.   }
  35. })
  36.  
  37. app.post('/logout', (req,res) => {
  38.   req.session.destroy(function(err) {
  39.     if(err) {
  40.       console.log(err)
  41.     } else {
  42.       res.redirect('/home')
  43.     }
  44.   })
  45. })
  46.  
  47. app.get('/home', (req,res) => {
  48.   res.render('home')
  49. })
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