fix spaces
This commit is contained in:
parent
f83c5aa423
commit
135c772723
7 changed files with 331 additions and 339 deletions
|
@ -9,61 +9,61 @@ import {db, UserRow} from "../types/db";
|
|||
let router = express.Router();
|
||||
|
||||
passport.use(new LocalStrategy(function verify(username, password, cb) {
|
||||
db.get("SELECT * FROM users WHERE username = ?", [username], function(err: Error, row: UserRow) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
if (!row) {
|
||||
return cb(null, false, {
|
||||
message: "Incorrect username or password."
|
||||
});
|
||||
}
|
||||
db.get("SELECT * FROM users WHERE username = ?", [username], function(err: Error, row: UserRow) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
if (!row) {
|
||||
return cb(null, false, {
|
||||
message: "Incorrect username or password."
|
||||
});
|
||||
}
|
||||
|
||||
crypto.pbkdf2(password, row.salt, 310000, 32, "sha256", function(err, hashedPassword) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
if (!crypto.timingSafeEqual(row.hashed_password, hashedPassword)) {
|
||||
return cb(null, false, {
|
||||
message: "Incorrect username or password."
|
||||
});
|
||||
}
|
||||
return cb(null, row);
|
||||
});
|
||||
});
|
||||
crypto.pbkdf2(password, row.salt, 310000, 32, "sha256", function(err, hashedPassword) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
if (!crypto.timingSafeEqual(row.hashed_password, hashedPassword)) {
|
||||
return cb(null, false, {
|
||||
message: "Incorrect username or password."
|
||||
});
|
||||
}
|
||||
return cb(null, row);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
passport.serializeUser(function(user:User, cb) {
|
||||
process.nextTick(function() {
|
||||
cb(null, {
|
||||
id: user.id,
|
||||
username: user.username
|
||||
});
|
||||
});
|
||||
process.nextTick(function() {
|
||||
cb(null, {
|
||||
id: user.id,
|
||||
username: user.username
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
passport.deserializeUser(function(user:User, cb) {
|
||||
process.nextTick(function() {
|
||||
return cb(null, user);
|
||||
});
|
||||
process.nextTick(function() {
|
||||
return cb(null, user);
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/login", function(req, res) {
|
||||
res.render("login");
|
||||
res.render("login");
|
||||
});
|
||||
|
||||
router.post("/login/password", passport.authenticate("local", {
|
||||
successRedirect: "/",
|
||||
failureRedirect: "/login"
|
||||
successRedirect: "/",
|
||||
failureRedirect: "/login"
|
||||
}));
|
||||
|
||||
router.post("/logout", function(req, res, next) {
|
||||
req.logout(function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.redirect("/");
|
||||
});
|
||||
req.logout(function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
res.redirect("/");
|
||||
});
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue