-
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.
- Loading branch information
0 parents
commit 484db88
Showing
11 changed files
with
429 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,35 @@ | ||
let bcrypt = require('bcrypt-nodejs') | ||
let SALT_WORK_FACTOR = 10; | ||
|
||
module.exports = { | ||
|
||
hash: function(user){ | ||
return new Promise((resolve, reject)=>{ | ||
bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) { | ||
if (err) reject(err); | ||
|
||
// hash the password using our new salt | ||
bcrypt.hash(user.password, salt, null, function(err, hash) { | ||
if (err) reject(err); | ||
|
||
// override the cleartext password with the hashed one | ||
user.password = hash; | ||
resolve(user); | ||
}); | ||
}); | ||
}) | ||
|
||
}, | ||
|
||
check: function(encryptedUser, user){ | ||
return new Promise((resolve, reject)=>{ | ||
bcrypt.compare(user.password, encryptedUser.password, function(err, isMatch) { | ||
if (err) reject(err); | ||
resolve(isMatch); | ||
}); | ||
}) | ||
|
||
} | ||
|
||
|
||
} |
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,7 @@ | ||
//Update the name of the controller below and rename the file. | ||
const template = require("../controllers/template.js") | ||
module.exports = function(app){ | ||
|
||
app.get('/', template.index); | ||
app.post('/createname', template.createName); | ||
} |
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 session = require('express-session'); | ||
const KnexSessionStore = require('connect-session-knex')(session); | ||
var knex = require('../db/knex.js'); | ||
|
||
module.exports = function(app){ | ||
const store = new KnexSessionStore({ | ||
knex: knex, | ||
tablename: 'sessions' // optional. Defaults to 'sessions' | ||
}); | ||
|
||
|
||
app.use(session({ | ||
secret: 'keyboard cat', | ||
cookie: { | ||
maxAge: 259200000 // 30 days | ||
}, | ||
resave: false, | ||
saveUninitialized: false, | ||
store: store | ||
})); | ||
} |
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,15 @@ | ||
const knex = require("../db/knex.js"); | ||
|
||
module.exports = { | ||
// CHANGE ME TO AN ACTUAL FUNCTION | ||
index: function(req, res) { | ||
res.render("index", {name: req.session.name}); | ||
}, | ||
createName: function(req, res){ | ||
req.session.name = req.body.name; | ||
|
||
req.session.save(()=>{ | ||
res.redirect('/') | ||
}) | ||
} | ||
} |
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,3 @@ | ||
var environment = process.env.NODE_ENV || 'development'; | ||
var config = require('../knexfile.js')[environment]; | ||
module.exports = require('knex')(config); |
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,25 @@ | ||
module.exports = { | ||
development: { | ||
client: 'pg', | ||
connection: { | ||
database: "users", | ||
host: "localhost" | ||
}, | ||
migrations: { | ||
directory: __dirname + '/db/migrations', | ||
}, | ||
seeds: { | ||
directory: __dirname + '/db/seeds', | ||
}, | ||
}, | ||
production: { | ||
client: 'pg', | ||
connection: process.env.DATABASE_URL, | ||
migrations: { | ||
directory: __dirname + '/db/migrations', | ||
}, | ||
seeds: { | ||
directory: __dirname + '/db/seeds/production', | ||
}, | ||
}, | ||
}; |
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 @@ | ||
{ | ||
"name": "assessment", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "server.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"bcrypt-nodejs": "0.0.3", | ||
"connect-session-knex": "^1.4.0", | ||
"ejs": "^2.5.7", | ||
"express": "^4.16.2", | ||
"express-session": "^1.15.6", | ||
"knex": "^0.13.0", | ||
"pg": "^7.3.0" | ||
} | ||
} |
Oops, something went wrong.