Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Midleware system by codernirmal with help of devstack #2

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
codernirmalnp wants to merge 1 commit into DevStack06:master
base: master
Choose a base branch
Loading
from codernirmalnp:master
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions helper/bcrypt.js
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /