blob: 8a97d203165ce6988b8de334f4088e5b15b23819 (
plain) (
blame)
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
|
const express = require('express')
const db = require ('../dbio')
const router = express.Router()
router.get('/contacts', function (req, res) {
// TODO: Implement code to fetch contacts from the database
table = db.getContacts();
res.send("AAAAAAAAAAAA");
});
// TODO: Add implementation for other necessary end-points
router.post('/login', function(req, res) {
var loginInfo = req.body;
var login = loginInfo.login;
var pwd = loginInfo.password;
// Query the database tbl_login with login and hashed password
rows = db.query(login,pwd);
// Provided there is no error, and the results set is assigned to a variable named rows:
if (rows.length >=1){// the length should be 0 or 1, but this will work for now
//success, set the session, return success
req.session.user=login;
res.json({status:'success'});
res.send("SUCC");
} else
res.send("FAIL");
res.json({status:'fail'});
});
router.get('/logout', function(req, res) {
if(!req.session.value) {
res.send('Session not started, can not logout!');
} else {
console.log ("Successfully Destroyed Session!");
req.session.destroy();
res.send("Session Complete!");
res.redirect('/login');
}
});
module.exports = router;
|