我想用护照本地mongoose中间件更改我的错误消息。但它不起作用:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var passportLocalMongoose = require('passport-local-mongoose');
var Account = new Schema({
username: String,
email: String
});
Account.plugin(passportLocalMongoose,{
IncorrectUsernameError: 'sdfsd',
IncorrectPasswordError: 'sdfsd'
});
var User = mongoose.model('Account', Account);
module.exports = User;
多数民众赞成我的Account.js和登录/注册工作完美
我的问题是,当我输入错误的用户名/密码时,会显示旧消息“错误的用户名或密码”。
答案 0 :(得分:2)
使用选项中的errorMessages
字段:
var options = {
errorMessages: {
MissingPasswordError: 'No password was given',
AttemptTooSoonError: 'Account is currently locked. Try again later',
TooManyAttemptsError: 'Account locked due to too many failed login attempts',
NoSaltValueStoredError: 'Authentication not possible. No salt value stored',
IncorrectPasswordError: 'Password or username are incorrect',
IncorrectUsernameError: 'Password or username are incorrect',
MissingUsernameError: 'No username was given',
UserExistsError: 'A user with the given username is already registered'
}
};
Account.plugin(passportLocalMongoose,options);
答案 1 :(得分:0)
您可以按照以下步骤进行操作:
Account.plugin(passportLocalMongoose,{usernameField:'email',errorMessages:{UserExistsError:'具有给定电子邮件的用户已被注册。'}});
答案 2 :(得分:-1)
您可以更改options
var options = {
MissingPasswordError: 'No password was given',
AttemptTooSoonError: 'Account is currently locked. Try again later',
TooManyAttemptsError: 'Account locked due to too many failed login attempts',
NoSaltValueStoredError: 'Authentication not possible. No salt value stored',
IncorrectPasswordError: 'Password or username are incorrect',
IncorrectUsernameError: 'Password or username are incorrect',
MissingUsernameError: 'No username was given',
UserExistsError: 'A user with the given username is already registered'
};
Account.plugin(passportLocalMongoose,options);