aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2021-04-16 19:33:08 -0500
committerMatthew Strapp <msattr@gmail.com>2021-04-16 19:33:08 -0500
commit4c2db76344d78a5cb93b51a1f14e8f5eb945317f (patch)
tree2f11b8e56ed9b291543019eee094a51d9b354115 /csci4131
parentFix typos because I am a fool (diff)
downloadhomework-4c2db76344d78a5cb93b51a1f14e8f5eb945317f.tar
homework-4c2db76344d78a5cb93b51a1f14e8f5eb945317f.tar.gz
homework-4c2db76344d78a5cb93b51a1f14e8f5eb945317f.tar.bz2
homework-4c2db76344d78a5cb93b51a1f14e8f5eb945317f.tar.lz
homework-4c2db76344d78a5cb93b51a1f14e8f5eb945317f.tar.xz
homework-4c2db76344d78a5cb93b51a1f14e8f5eb945317f.tar.zst
homework-4c2db76344d78a5cb93b51a1f14e8f5eb945317f.zip
aaaaaaaaaaaaaaaaaaaaaa
Diffstat (limited to 'csci4131')
-rwxr-xr-xcsci4131/hw5/strap012_hw5/package.json1
-rw-r--r--csci4131/hw6/strap012_hw6/api/utilities.js30
-rw-r--r--csci4131/hw6/strap012_hw6/dbio.js8
3 files changed, 22 insertions, 17 deletions
diff --git a/csci4131/hw5/strap012_hw5/package.json b/csci4131/hw5/strap012_hw5/package.json
index 1253c2a..90f2542 100755
--- a/csci4131/hw5/strap012_hw5/package.json
+++ b/csci4131/hw5/strap012_hw5/package.json
@@ -4,7 +4,6 @@
"description": "Assignment 5",
"main": "createServer.js",
"scripts": {
- "start": "node createServer.js",
"test": "node createServer.js"
},
"author": "strap012",
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) {
diff --git a/csci4131/hw6/strap012_hw6/dbio.js b/csci4131/hw6/strap012_hw6/dbio.js
index 538fa5a..ab3ec42 100644
--- a/csci4131/hw6/strap012_hw6/dbio.js
+++ b/csci4131/hw6/strap012_hw6/dbio.js
@@ -16,10 +16,9 @@ connection.connect(function(err) {
console.log("Connected to MYSQL database!");
});
-function passcheck(user,pass) {
+async function passcheck(user,pass) {
let ret = '';
connection.query('SELECT * FROM tbl_accounts', function(err,rows,fields) {
-
if (err) throw err;
if (rows.length == 0) {
console.log("There are no entries in the accounts field!");
@@ -32,8 +31,9 @@ function passcheck(user,pass) {
}
}
}
- });
return ret;
+ });
+
}
function getContacts() {
@@ -68,4 +68,4 @@ var ISBN = '0000002345';
// console.log ("Version 2 values inserted");
// });
-
+exports.query = passcheck;