-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd922dc
commit 328ab4d
Showing
5 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
exports.get = (req, res) => { | ||
const { type } = req.params; | ||
let errorMsg = ""; | ||
if (type == 'pw') { | ||
errorMsg = "Password incorrect" | ||
} else if (type == 'un') { | ||
errorMsg = "Username not found. Please note usernames are case sensitive" | ||
} | ||
res.render("formError", { message: errorMsg }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
const db = require('../../db/db_connection'); | ||
const bcrypt = require('bcryptjs'); | ||
const db = require("../../db/db_connection"); | ||
const bcrypt = require("bcryptjs"); | ||
const checkUser = object => { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
const name = object.name; | ||
const password = object.password; | ||
db.query(`SELECT password FROM users WHERE name = '${name}';`) | ||
.then (res => { | ||
const hash = res[0].password; | ||
bcrypt.compare(password, hash, (err, res) => { | ||
if (err) reject(`error validating password: ${err}`); | ||
else { | ||
console.log('password is valid?: ', res); | ||
resolve(res); | ||
} | ||
}) | ||
}) | ||
.catch(e => reject(`Couldn't update db: ${e}`)); | ||
}) | ||
} | ||
.then(res => { | ||
if (res.length < 1) { | ||
reject("user not found"); | ||
} else { | ||
const hash = res[0].password; | ||
bcrypt.compare(password, hash, (err, res) => { | ||
if (err) reject(`error hashing pw: ${err}`); | ||
else { | ||
// console.log("password is valid?: ", res); | ||
resolve(res); | ||
} | ||
}); | ||
} | ||
}) | ||
.catch(e => reject(`Couldn't update db: ${e}`)); | ||
}); | ||
}; | ||
|
||
module.exports = checkUser; | ||
// Log in: | ||
// get user data where name = username inputted | ||
// compare hashed input to hashed password | ||
// return true/false? | ||
// get user data where name = username inputted | ||
// compare hashed input to hashed password | ||
// return true/false? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<form> | ||
<h2>{{message}}</h2> | ||
<a href="/log-in"><button type="button">Try Again</button><a> | ||
</form> |