aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131/hw6/strap012_hw6/api
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2021-04-16 12:58:44 -0500
committerMatthew Strapp <msattr@gmail.com>2021-04-16 12:58:44 -0500
commit43865930f8580f6fe97ea9f54686a1b805358a6d (patch)
tree67a884ca82ab1c393baeb87059847fed7ff1cc03 /csci4131/hw6/strap012_hw6/api
parentI don't get Express routers (diff)
downloadhomework-43865930f8580f6fe97ea9f54686a1b805358a6d.tar
homework-43865930f8580f6fe97ea9f54686a1b805358a6d.tar.gz
homework-43865930f8580f6fe97ea9f54686a1b805358a6d.tar.bz2
homework-43865930f8580f6fe97ea9f54686a1b805358a6d.tar.lz
homework-43865930f8580f6fe97ea9f54686a1b805358a6d.tar.xz
homework-43865930f8580f6fe97ea9f54686a1b805358a6d.tar.zst
homework-43865930f8580f6fe97ea9f54686a1b805358a6d.zip
Get started on DB work, still needs much work
Diffstat (limited to 'csci4131/hw6/strap012_hw6/api')
-rw-r--r--csci4131/hw6/strap012_hw6/api/utilities.js33
1 files changed, 32 insertions, 1 deletions
diff --git a/csci4131/hw6/strap012_hw6/api/utilities.js b/csci4131/hw6/strap012_hw6/api/utilities.js
index eda6e72..8a97d20 100644
--- a/csci4131/hw6/strap012_hw6/api/utilities.js
+++ b/csci4131/hw6/strap012_hw6/api/utilities.js
@@ -1,11 +1,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
- res.send("AAAAAAAAAAAA")
+ 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;