-
Notifications
You must be signed in to change notification settings - Fork 15
lab 18 Jeremiah #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jtwalters25
wants to merge
9
commits into
codefellows-javascript-401d13:master
Choose a base branch
from
jtwalters25:part3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
lab 18 Jeremiah #34
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
76ca969
day1cfgram
jtwalters25 2bdf54b
part1
jtwalters25 170c035
day 2 lab 17
jtwalters25 03eac0c
indentation
jtwalters25 cb6faf5
new routes and test written.
jtwalters25 e2ccd16
test passing without after serveroff toggle
jtwalters25 ca7aeb5
added travis
jtwalters25 1f3c5df
coveralls added
jtwalters25 8fa79bd
testing branch
jtwalters25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
service_name: travis-ci | ||
repo_token: 6BGoLqVz7XNLz8jPtdoB9SyoY2YsUFbNZ |
This file contains hidden or 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,6 @@ | ||
PORT='8000' | ||
MONGODB_URI='mongodb://localhost/cfgram' | ||
APP_SECRETS='tribetight' | ||
AWS_BUCKET='codefellowgram' | ||
AWS_ACCESS_KEY_ID='AKIAJNJCN6LSBL6C4TUQ' | ||
AWS_SECRET_ACCESS_KEY='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' |
This file contains hidden or 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 @@ | ||
{ | ||
"rules": { | ||
"no-console": "off", | ||
"indent": [ "error", 2 ], | ||
"quotes": [ "error", "single" ], | ||
"semi": ["error", "always"], | ||
"linebreak-style": [ "error", "unix" ] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"mocha": true, | ||
"jasmine": true | ||
}, | ||
"ecmaFeatures": { | ||
"modules": true, | ||
"experimentalObjectRestSpread": true, | ||
"impliedStrict": true | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
This file contains hidden or 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,95 @@ | ||
# Created by https://www.gitignore.io/api/node,osx,windows,linux | ||
### Linux ### | ||
*~ | ||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
# KDE directory preferences | ||
.directory | ||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
# Runtime data | ||
data/ | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
# Coverage directory used by tools like istanbul | ||
coverage | ||
# nyc test coverage | ||
.nyc_output | ||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
# node-waf configuration | ||
.lock-wscript | ||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
# Typescript v1 declaration files | ||
typings/ | ||
# Optional npm cache directory | ||
.npm | ||
# Optional eslint cache | ||
.eslintcache | ||
# Optional REPL history | ||
.node_repl_history | ||
# Output of 'npm pack' | ||
*.tgz | ||
# Yarn Integrity file | ||
.yarn-integrity | ||
# dotenv environment variables file | ||
#ignore .env file | ||
.env/ | ||
### OSX ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
# Icon must end with two \r | ||
Icon | ||
# Thumbnails | ||
._* | ||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
### Windows ### | ||
# Windows thumbnail cache files | ||
Thumbs.db | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
# Folder config file | ||
Desktop.ini | ||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
# Windows shortcuts | ||
*.lnk | ||
# End of https://www.gitignore.io/api/node,osx,windows,linux |
This file contains hidden or 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,23 @@ | ||
'use strict'; | ||
|
||
const gulp = require('gulp'); | ||
const eslint = require('gulp-eslint'); | ||
const mocha = require ('gulp-mocha'); | ||
|
||
gulp.task('test', function(){ | ||
gulp.src('./test/*-test.js', { read: false}) | ||
.pipe(mocha({ reporter: 'spec'})); | ||
}); | ||
|
||
gulp.task('lint', function() { | ||
return gulp.src(['**/*.js', '!node_modules']) | ||
.pipe(eslint()) | ||
.pipe(eslint.format()) | ||
.pipe(eslint.failAfterError()); | ||
}); | ||
|
||
gulp.task('dev', function(){ | ||
gulp.watch(['**/*.js', '!node_modules/**'], ['lint', 'test']); | ||
}); | ||
|
||
gulp.task('default', ['dev']); |
This file contains hidden or 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,36 @@ | ||
'use strict'; | ||
|
||
const createError = require('http-errors'); | ||
const debug = require('debug')('cfgram: basic-auth-middleware'); | ||
|
||
module.exports = function(req, res, next) { | ||
debug('basic auth'); | ||
|
||
var authHeader = req.headers.authorization; | ||
if (!authHeader){ | ||
return next(createError(401, 'authorization header required')); | ||
} | ||
|
||
var base64str = authHeader.split('Basic ')[1]; | ||
if (!base64str){ | ||
return next(createError(401, 'username and password required')); | ||
} | ||
|
||
var utf8str = new Buffer(base64str, 'base64').toString(); | ||
var authArr = utf8str.split(':'); | ||
|
||
req.auth = { | ||
username: authArr[0], | ||
password: authArr[1] | ||
}; | ||
|
||
if (!req.auth.username) { | ||
return next(createError(401, 'username required')); | ||
}; | ||
|
||
if (!req.auth.password) { | ||
return next(createError(401, 'password required')); | ||
}; | ||
|
||
next(); | ||
}; |
This file contains hidden or 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,33 @@ | ||
'use strict'; | ||
|
||
const jwt = require('jsonwebtoken'); | ||
const createError = require('http-errors'); | ||
const debug = require('debug')('cfgram:bearer-auth-middleware'); | ||
|
||
const User = require('../model/user.js'); | ||
|
||
module.exports = function(req, res, next) { | ||
debug('bearer'); | ||
var authHeader = req.headers.authorization; | ||
if (!authHeader) { | ||
return next(createError(401, 'authorization header required')); | ||
} | ||
|
||
var token = authHeader.split('Bearer ')[1]; | ||
if (!token) { | ||
return next(createError(401, 'token required')); | ||
} | ||
|
||
jwt.verify(token, process.env.APP_SECRETS, (err, decoded) => { | ||
if (err) return next(err); | ||
|
||
User.findOne({ findHash: decoded.token }) | ||
.then( user => { | ||
req.user = user; | ||
next(); | ||
}) | ||
.catch(err => { | ||
next(createError(401, err.message)); | ||
}); | ||
}); | ||
}; |
This file contains hidden or 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,28 @@ | ||
'use strict'; | ||
|
||
const createError = require('http-errors'); | ||
const debug = require('debug')('cfgram:error-middleware'); | ||
|
||
module.exports = function(err, req, res, next){ | ||
debug('error middleware'); | ||
|
||
console.error('msg:', err.message); | ||
console.error('name:', err.name) | ||
|
||
if (err.status){ | ||
res.status(err.status).send(err.name); | ||
next(); | ||
return; | ||
} | ||
|
||
if (err.name === 'ValidationError'){ | ||
err = createError(400, err.message); | ||
res.status(err.status).send(err.name); | ||
next(); | ||
return; | ||
} | ||
|
||
err = createError(500, err.message); | ||
res.status(err.status).send(err.name); | ||
next(); | ||
}; |
This file contains hidden or 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,17 @@ | ||
'use strict'; | ||
|
||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
//Schema | ||
const flickSchema = Schema({ | ||
name: { type: String, required: true }, | ||
desc: { type: String, required: true }, | ||
userID: { type: Schema.Types.ObjectId, required: true },//make sure its part of the correct gallery | ||
galleryID: { type: Schema.Types.ObjectId, required: true }, | ||
imageURI: { type: String, required: true, unique: true },//what comes back from s3 | ||
objectKey: { type: String, required: true, unique: true },//also comes back from s3 | ||
created: { type: Date, default: Date.now } | ||
}); | ||
|
||
module.exports= mongoose.model('flick', flickSchema); |
This file contains hidden or 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,13 @@ | ||
'use strict'; | ||
|
||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
const gallerySchema = Schema({ | ||
name: { type: String, required: true }, | ||
desc: { type: String, required: true }, | ||
created: { type: Date, required: true, default: Date.now }, | ||
userID: { type: mongoose.Schema.Types.ObjectId, required: true } | ||
}); | ||
|
||
module.exports = mongoose.model('gallery', gallerySchema); |
This file contains hidden or 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,75 @@ | ||
'use strict'; | ||
|
||
const crypto = require('crypto'); | ||
const bcrypt = require('bcrypt'); | ||
const jwt = require('jsonwebtoken'); | ||
const mongoose = require('mongoose'); | ||
const createError = require('http-errors'); | ||
const Promise = require('bluebird'); | ||
const debug = require('debug')('cfgram:user'); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const userSchema = Schema({ | ||
username: { type: String, required: true, unique: true }, | ||
email: { type: String, required: true, unique: true }, | ||
password: { type: String, required: true }, | ||
findHash: { type: String, unique: true } | ||
}); | ||
|
||
userSchema.methods.generatePasswordHash = function(password) { | ||
debug('generatePasswordHash'); | ||
|
||
return new Promise((resolve, reject) => { | ||
bcrypt.hash(password, 10, (err, hash) => { | ||
if (err) return reject(err); | ||
this.password = hash; | ||
resolve(this); | ||
}); | ||
}); | ||
}; | ||
|
||
userSchema.methods.comparePasswordHash = function(password) { | ||
debug('comparePasswordHash'); | ||
|
||
return new Promise((resolve, reject) => { | ||
bcrypt.compare(password, this.password, (err, valid) => { | ||
if (err) return reject(err); | ||
if (!valid) return reject(createError(401, 'wrong password')); | ||
resolve(this); | ||
}); | ||
}); | ||
}; | ||
|
||
userSchema.methods.generateFindHash = function(){ | ||
debug('generateFindHash'); | ||
|
||
return new Promise((resolve, reject) => { | ||
let attempts = 0; | ||
|
||
_generateFindHash.call(this); | ||
|
||
function _generateFindHash(){ | ||
this.findHash = crypto.randomBytes(32).toString('hex'); | ||
this.save() | ||
.then( () => resolve(this.findHash)) | ||
.catch( err => { | ||
if (attempts > 3) return reject(err); | ||
attempts++; | ||
_generateFindHash.call(this); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
userSchema.methods.generateToken = function(){ | ||
debug('generateToken'); | ||
|
||
return new Promise((resolve, reject) => { | ||
this.generateFindHash() | ||
.then(findHash => resolve(jwt.sign({ token: findHash }, process.env.APP_SECRETS))) | ||
.catch( err => reject(err)); | ||
}); | ||
}; | ||
|
||
module.exports = mongoose.model('user', userSchema); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you are taking notes to remind yourself what things are. I take notes in my code as well. Sometimes if I have questions I will note them in there as well and just remove them before pushing.