aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131/hw6/strap012_hw6/api
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2021-04-16 21:37:26 -0500
committerMatthew Strapp <msattr@gmail.com>2021-04-16 21:37:26 -0500
commit0c7bb17b8c955254c2db61a5fe9c8240ea1357e2 (patch)
tree1aa1a6234807c7b03339cad7b9c04ad1a0b976ed /csci4131/hw6/strap012_hw6/api
parentaaaaaaaaaaaaaaaaaaaaaa (diff)
downloadhomework-0c7bb17b8c955254c2db61a5fe9c8240ea1357e2.tar
homework-0c7bb17b8c955254c2db61a5fe9c8240ea1357e2.tar.gz
homework-0c7bb17b8c955254c2db61a5fe9c8240ea1357e2.tar.bz2
homework-0c7bb17b8c955254c2db61a5fe9c8240ea1357e2.tar.lz
homework-0c7bb17b8c955254c2db61a5fe9c8240ea1357e2.tar.xz
homework-0c7bb17b8c955254c2db61a5fe9c8240ea1357e2.tar.zst
homework-0c7bb17b8c955254c2db61a5fe9c8240ea1357e2.zip
finish hw6
Diffstat (limited to 'csci4131/hw6/strap012_hw6/api')
-rw-r--r--csci4131/hw6/strap012_hw6/api/utilities.js34
1 files changed, 17 insertions, 17 deletions
diff --git a/csci4131/hw6/strap012_hw6/api/utilities.js b/csci4131/hw6/strap012_hw6/api/utilities.js
index 8036c29..65a087f 100644
--- a/csci4131/hw6/strap012_hw6/api/utilities.js
+++ b/csci4131/hw6/strap012_hw6/api/utilities.js
@@ -4,13 +4,11 @@ const router = express.Router()
router.use(express.urlencoded({ extended: true }))
router.get('/contacts', function (req, res) {
- // TODO: Implement code to fetch contacts from the database
- table = db.getContacts();
- res.send("AAAAAAAAAAAA");
+ db.getContacts().then(function(table) {
+ res.send(table)
+ });
});
-
-// TODO: Add implementation for other necessary end-points
router.post('/login', async function(req, res) {
var loginInfo = req.body;
var login = loginInfo.login;
@@ -18,31 +16,33 @@ router.post('/login', async function(req, res) {
let rows = [];
// Query the database tbl_login with login and hashed password
- try {
- rows = await db.query(login, pwd);
- }
- finally {
+ db.query(login, pwd).then(function(rows) {
// 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' });
- }
+ } else {
+ res.json({ status: 'fail' });
+ }
+ });
+
});
router.get('/logout', function(req, res) {
- if(!req.session.value) {
+ if(!req.session.user) {
res.send('Session not started, can not logout!');
} else {
- console.log ("Successfully Destroyed Session!");
req.session.destroy();
- res.send("Session Complete!");
res.redirect('/login');
}
});
+router.post('/addContact', function(req, res) {
+ var contact = req.body;
+ db.addContact(contact).then(function() {
+ res.redirect('/contacts');
+ });
+});
+
module.exports = router;