Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
troyamelotte committed Apr 18, 2018
0 parents commit 484db88
Show file tree
Hide file tree
Showing 11 changed files with 429 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions config/hasher.js
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);
});
})

}


}
7 changes: 7 additions & 0 deletions config/routes.js
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);
}
21 changes: 21 additions & 0 deletions config/sessions.js
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
}));
}
15 changes: 15 additions & 0 deletions controllers/template.js
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('/')
})
}
}
3 changes: 3 additions & 0 deletions db/knex.js
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);
25 changes: 25 additions & 0 deletions knexfile.js
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',
},
},
};
21 changes: 21 additions & 0 deletions package.json
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"
}
}
Loading

0 comments on commit 484db88

Please sign in to comment.