简体   繁体   English

ERR_HTTP_INVALID_STATUS_CODE — 登录网站失败时服务器关闭

[英]ERR_HTTP_INVALID_STATUS_CODE — server goes off when logging on the website fails

I want to do authentication on my website.我想在我的网站上进行身份验证。 I did it with passport.js, and everything seems to be good, but there is one big issue.我用passport.js做的,一切似乎都很好,但是有一个大问题。 If i type wrong username or password while logging in, the whole server goes down.I have got ' if ' statements in my code which should show flash massages when password is wrong.如果我在登录时输入错误的用户名或密码,整个服务器就会关闭。我的代码中有“if”语句,当密码错误时应该显示 flash 消息。 It works perfectly with registration.它与注册完美配合。 Below are parts of code in my files with login authentication and whole error from the console.以下是我的文件中的部分代码,其中包含登录身份验证和来自控制台的整个错误。

error code错误代码

https://prnt.sc/s70s5m https://prnt.sc/s70s5m

file routes.js文件路由.js

const User            = require("../models/user");
const Post            = require("../models/post");

module.exports = function(app,passport){

app.get("/login", function(req,res){
    res.render("login", {message:req.flash("loginMessage")});
});

app.post("/login", passport.authenticate("local-login", {
    successRedirect:"/",
    failureRedorect:"/login",
    failureFlash:true
}))};

file passport.js文件护照.js

   passport.use('local-login', new LocalStrategy({
    passReqToCallback : true
},
function(req, username, password, done) {

    User.findOne({ 'local.username' :  username }, function(err, user) {
        if (err)
            return done(err);

        if (!user)
        {
            return done(null, false, req.flash('loginMessage', 'No user found.'));
        }
        if (!user.validPassword(password))
        {
            return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.')); 
        }
        else
             return done(null, user);
    });

}));

file user.js文件 user.js

const mongoose = require("mongoose"),
  bcrypt   = require("bcrypt-nodejs");

var userSchema = new mongoose.Schema({
    local: {
        username:String,
        password:String
    }
});

userSchema.methods.generateHash = function(password) {
    return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
userSchema.methods.validPassword = function(password) {
    return bcrypt.compareSync(password, this.local.password);
};

It's typed wrong in failureRedorect:"/login" .failureRedorect:"/login"中输入错误。 Correct is: failureRedirect.正确的是:failureRedirect。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RangeError [ERR_HTTP_INVALID_STATUS_CODE]:无效状态代码:4 - RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: 4 为什么我收到 ERR_HTTP_INVALID_STATUS_CODE? - Why I'm getting ERR_HTTP_INVALID_STATUS_CODE? RangeError [ERR_HTTP_INVALID_STATUS_CODE]:无效的状态代码:[object Object] 错误表达 4.16 - RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: [object Object] error express 4.16 我收到 RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined - I am getting RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined 如何修复 RangeError [ERR_HTTP_INVALID_STATUS_CODE]:无效状态代码:未定义我在尝试注册用户时收到此错误 - How to fix RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined i got this error when am trying to register user Node.js中的错误-UnhandledPromiseRejectionWarning:RangeError [ERR_HTTP_INVALID_STATUS_CODE] - Error in Node.js - UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE] 运行http服务器时出现ERR_INVALID_REDIRECT - ERR_INVALID_REDIRECT when running http-server 获取索引Azure搜索失败“对预检的响应具有无效的HTTP状态代码403” - Get Index Azure Search Fails 'Response for preflight has invalid HTTP status code 403' 在 chrome 中向 python 服务器发送请求时出现 ERR_INVALID_HTTP_RESPONSE - ERR_INVALID_HTTP_RESPONSE when sending request in chrome to python server AngularJS POST 失败:预检响应具有无效的 HTTP 状态代码 404 - AngularJS POST Fails: Response for preflight has invalid HTTP status code 404
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM