From 4c2db76344d78a5cb93b51a1f14e8f5eb945317f Mon Sep 17 00:00:00 2001 From: Matthew Strapp Date: Fri, 16 Apr 2021 19:33:08 -0500 Subject: aaaaaaaaaaaaaaaaaaaaaa --- csci4131/hw6/strap012_hw6/api/utilities.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'csci4131/hw6/strap012_hw6/api') diff --git a/csci4131/hw6/strap012_hw6/api/utilities.js b/csci4131/hw6/strap012_hw6/api/utilities.js index 8a97d20..8036c29 100644 --- a/csci4131/hw6/strap012_hw6/api/utilities.js +++ b/csci4131/hw6/strap012_hw6/api/utilities.js @@ -1,6 +1,7 @@ const express = require('express') const db = require ('../dbio') 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 @@ -10,23 +11,28 @@ router.get('/contacts', function (req, res) { // TODO: Add implementation for other necessary end-points -router.post('/login', function(req, res) { +router.post('/login', async function(req, res) { var loginInfo = req.body; var login = loginInfo.login; var pwd = loginInfo.password; + let rows = []; // 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'}); - }); + try { + rows = await db.query(login, pwd); + } + finally { + // 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) { -- cgit v1.2.3