我正在尝试在风帆0.10.0-rc9中设置密码确认。这是一个新用户注册。当我在两个字段中使用相同的密码时,控制台确认它已获取相同的密码,然后吐出他们不匹配的错误。我想知道我错过了什么...
模型 - user.js - 看起来像 https://github.com/mrcn/C_Express/blob/master/api/models/User.error.js
module.exports = {
schema: true,
attributes: {
name: {
type: "string",
required: true
},
email: {
type: "string",
email: true,
required: true,
unique: true
},
encryptedPassword: {
type: "string"
},
toJSON: function() {
var obj = this.toObject();
delete obj.password;
delete obj.confirmation;
delete obj.encryptedPassword;
delete obj._csrf;
return obj;
}
},
beforeCreate: function (values, next) {
console.log("Called beforeCreate User ");
console.log(values);
if(!values.password || values.password != values.confirmation) {
console.log("\n if statement call \n");
return next({
err : ["password dont match."]
});
}
}
};
表单如下所示: https://github.com/mrcn/C_Express/blob/master/views/user/new.ejs
<input type="text" class="form-control" placeholder="your name" name="name" required />
<input type="email" class="form-control" placeholder="email address" name="email" data-parsley-trigger="change" required />
<input type="password" class="form-control" placeholder="password" name="password" required />
<input type="password" class="form-control" placeholder="confirmation" name="confirmation" required />
<br />
<input type="submit" class="btn btn-lg btn-primary btn-block" value="Create Account" />
<input type="hidden" name="_csrf" value="<% _csrf %>" />
当我使用随机&#34; wer&#34;对于一切,控制台日志&#34;
Called beforeCreate User
{ name: 'wer',
email: 'wer@wer.com',
password: 'wer',
confirmation: 'wer',
_csrf: '',
id: null }
if statement call
{ err: [ 'password dont match.' ] }
答案 0 :(得分:5)
两个地方的拼写password
可能相同吗? :P
if(!values.password || values.pasword != values.confirmation) {
^oops
答案 1 :(得分:0)
beforeCreate 更改为 beforeValidate Ç