-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
executable file
·82 lines (60 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var bodyParser = require('body-parser')
var express = require('express')
var hbs = require('express-handlebars')
var path = require('path')
var passport = require('passport')
var expressSession = require('express-session')
var LocalStrategy = require('passport-local').Strategy
var index = require('./routes/index')
var db = require('./db/db')
var configureAuth = require('./auth/configureAuth')
var PORT = process.env.PORT || 3030
var SESSION_KEY = process.env.SESSION_KEY || "Miaou"
var app = express()
app.use(expressSession({secret: SESSION_KEY}))
app.use(passport.initialize())
app.use(passport.session())
passport.serializeUser(function(user, done) {
done(null, user.id)
})
passport.deserializeUser(function(id, done) {
db.findById(id)
.then(function (users) {
done(null, users[0])
})
.catch(function (err) {
done(err)
})
})
passport.use('login', new LocalStrategy(configureAuth.loginStrategy))
passport.use('signup', new LocalStrategy({
passReqToCallback : true
}, configureAuth.registerStrategy))
app.use(express.static('public'))
app.engine('hbs', hbs())
app.set('view engine', 'hbs')
app.set('views', path.join(__dirname, 'views'))
app.use(bodyParser.urlencoded({ extended: true }))
app.get('/', index.get)
app.post('/login', passport.authenticate('login', {
successRedirect: '/profile',
failureRedirect: '/'
}))
app.get('/logout', function(req, res) {
req.logout()
res.redirect('/')
})
app.get('/profile', index.profile)
app.get('/searchCar', index.searchCar)
app.get('/register', index.register)
app.post('/registerUser', passport.authenticate('signup', {
successRedirect: '/profile',
failureRedirect: '/register'
}))
app.get('/sms/:id', index.sms)
app.get('/update', index.update)
app.post('/updateUser', index.updateUser)
app.get('/sms/:id', index.sms)
app.listen(PORT, function () {
console.log('Listening on port', PORT)
})