forked from sunuwars/DJES
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first sessionID functionality - on registration > relates #20
- Loading branch information
1 parent
94c3797
commit d104c36
Showing
4 changed files
with
80 additions
and
5 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
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 |
---|---|---|
|
@@ -17,11 +17,25 @@ const passwords = { | |
dbConnection.query( | ||
`INSERT INTO users (name, email, fav_colour, password_hash) VALUES ($1, $2, $3, $4)`, | ||
[name, email, favColour, hashedPassword], | ||
// `INSERT INTO users (name, email, fav_colour, password_hash) VALUES ('${name}', '${email}', '${favColour}', '${hashedPassword}')`, | ||
// `INSERT INTO users (name, email, fav_colour, password_hash) VALUES ('Joe', '[email protected]', '0947dd', '$2b$12$9KMMDuR2Le5n1.tl1LYqOuVCRXjwpIRfj0RafQa/mppqgNTD7.P8u')`, | ||
(err, res) => { | ||
if (err) return cb(err); | ||
return cb(null, res); | ||
} | ||
); | ||
}, | ||
|
||
storeSession: (sessionID, email, cb) => { | ||
console.log("session ID: ", sessionID) | ||
dbConnection.query( | ||
`INSERT INTO active_sessions (session_id, email) VALUES ($1, $2)`, | ||
[sessionID, email], | ||
(err, res) => { | ||
if(err) return cb(err); | ||
return cb(null, res); | ||
} | ||
) | ||
} | ||
|
||
// takes in hash of password, compares against hash from database | ||
|
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,21 @@ | ||
const crypto = require("crypto"); | ||
|
||
|
||
function random(length = 24){ | ||
return new Promise((resolve, reject) => { | ||
crypto.randomBytes(48, (err, buffer) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve (buffer.toString("hex")) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
|
||
|
||
|
||
var sessionID = random() | ||
.then(dsdsfd => console.log(dsdsfd)) | ||
|