-
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
Amritesh Srivastava
committed
Apr 7, 2020
1 parent
d18716c
commit 83a9c72
Showing
23 changed files
with
980 additions
and
2 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 @@ | ||
/node_modules |
Empty file.
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 @@ | ||
module.exports = { | ||
'secret': 'thisissomethingsecrete', | ||
'database': 'mongodb://127.0.0.1:27017/auth' | ||
}; |
Empty file.
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,9 @@ | ||
const passport = require('passport'); | ||
const express = require('express'); | ||
const dashboardService = require('../services/dashboard'); | ||
|
||
let router = express.Router(); | ||
|
||
router.get('/', passport.authenticate('jwt', { session: false }), dashboardService.getDashboard); | ||
|
||
module.exports = router; |
Empty file.
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,8 @@ | ||
function index(request, response) { | ||
console.log('home controller'); | ||
response.json('This is home route'); | ||
} | ||
|
||
module.exports = { | ||
index: index | ||
}; |
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,17 @@ | ||
const express = require('express'); | ||
const loginService = require('../services/login'); | ||
|
||
let router = express.Router(); | ||
|
||
|
||
// router.post('/', loginService.loginUser); | ||
// loginService.loginUser(req, res); | ||
|
||
function login(request, response) { | ||
console.log('login controller'); | ||
loginService.loginUser(request, response); | ||
} | ||
|
||
module.exports = { | ||
login: login | ||
}; |
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,8 @@ | ||
const express = require('express'); | ||
const registerService = require('../services/register'); | ||
|
||
let router = express.Router(); | ||
|
||
router.post('/', registerService.registerUser); | ||
|
||
module.exports = router; |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const mongoose = require('mongoose'); | ||
const bcrypt = require('bcrypt'); | ||
|
||
const UserSchema = new mongoose.Schema({ | ||
email: { | ||
type: String, | ||
lowercase: true, | ||
unique: true, | ||
required: true | ||
}, | ||
password: { | ||
type: String, | ||
required: true | ||
}, | ||
role: { | ||
type: String, | ||
enum: ['Client', 'Manager', 'Admin'], | ||
default: 'Client' | ||
} | ||
}); | ||
|
||
UserSchema.pre('save', function(next) { | ||
let user = this; | ||
|
||
if (this.isModified('password') || this.isNew) { | ||
bcrypt.genSalt(10, (err, salt) => { | ||
if (err) { | ||
console.log(err); | ||
return next(err); | ||
} | ||
|
||
bcrypt.hash(user.password, salt, (err, hash) => { | ||
if (err) { | ||
console.log(err); | ||
return next(err); | ||
} | ||
|
||
user.password = hash; | ||
next(); | ||
}); | ||
}); | ||
} else { | ||
return next(); | ||
} | ||
}); | ||
|
||
// Create method to compare password input to password saved in database | ||
UserSchema.methods.comparePassword = function(pw, cb) { | ||
bcrypt.compare(pw, this.password, function(err, isMatch) { | ||
if (err) { | ||
return cb(err); | ||
} | ||
|
||
cb(null, isMatch); | ||
}); | ||
}; | ||
|
||
module.exports = mongoose.model('User', UserSchema); |
Oops, something went wrong.