-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
65 lines (56 loc) · 1.69 KB
/
app.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
const express=require('express');
const app=express();
const passport=require('passport')
const passportlocal=require('passport-local')
const session=require('cookie-session')
const bodyParser=require('body-parser')
const mongoose=require('mongoose')
const student=require('./students/model.js')
const md5=require('md5')
mongoose.connect(process.env.MLAB)
app.use(session({name:'session',keys:[process.env.secret]}))
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(passport.initialize())
app.use(passport.session())
app.set('view engine','ejs')
app.use(express.static(__dirname + '/public'));
function findUser (username, callback) {
student.userdata(username,function (err,data) {
if(err)
{
return callback(err,null)
}else if(data==null) {
return callback(null,'not registered')
}else {
return callback(null,data)
}
})
}
passport.serializeUser(function (user, cb) {
cb(null, user.regno)
})
passport.deserializeUser(function (username, cb) {
findUser(username, cb)
})
passport.use(new passportlocal.Strategy(function (username,password,done) {
findUser(username,function (err,data) {
if(err){
return done(err,null)
}else if(data==null) {
return done(null,false)
}else if(data.password==md5(password)) {
console.log("going");
return done(null,data)
}
return done(null,false)
})
}))
app.use('/',require('./routes/default.js'))
app.use('/course',require('./routes/course.js'))
app.use('/v1/course',require('./v1/course/course.js'))
app.use('/v2/course',require('./v2/course/course.js'))
app.use('/v1/student',require('./v1/student/student.js'))
app.use('/v2/student',require('./v2/student/student.js'))
app.listen(8080);