FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Midleware system by codernirmal with help of devstack by codernirmalnp · Pull Request #2 · DevStack06/Blog-Server · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (6) .json  (2) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
28 changes: 28 additions & 0 deletions helper/bcrypt.js
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 @@
const bcrypt = require('bcrypt');
const saltRounds = 10;
function compare(plaintxt,hash){
return bcrypt.compare(plaintxt, hash).then(function(result) {
if(result){
return true;
}
else{
return false;
}
});
}
function hash(plaintxt)
{
return bcrypt.hash(plaintxt, saltRounds).then(function(hash) {
if(hash)
{
return hash;
}
else{
return;
}


});
}
module.exports.Hash=hash;
module.exports.Compare=compare
30 changes: 30 additions & 0 deletions middleware/auth.js
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,30 @@
const User = require("../models/users.model");
module.exports={
checkusername:async function(req,res,next){
const username=req.body.username;
const user= await User.findOne({username:username});
if(user != null)
{
return res.status(422).json({Status:false,errorName:"username"})

}


next();

},
checkemail:async function(req,res,next)
{
const email=req.body.email;
const checkEmail=await User.findOne({email:email});
if(checkEmail != null)
{

return res.status(422).json({Status:false,errorName:"email"})

}

next();

}
}
4 changes: 2 additions & 2 deletions middleware.js → middleware/middleware.js
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
@@ -1,9 +1,8 @@
const jwt = require("jsonwebtoken");
const config = require("./config");
const config = require("../config");

let checkToken = (req, res, next) => {
let token = req.headers["authorization"];
console.log(token);
token = token.slice(7, token.length);
if (token) {
jwt.verify(token, config.key, (err, decoded) => {
Expand All @@ -25,6 +24,7 @@ let checkToken = (req, res, next) => {
}
};


module.exports = {
checkToken: checkToken,
};
Loading

Back | FazBrowse Home | New Git URL