我们的登录模型仅要求用户输入用户名和密码,电子邮件是可选的,但是环回用户模型需要用户输入电子邮件才能创建新用户。
有没有一种方法可以在 Strongloop 中创建新用户而无需输入电子邮件?
最佳答案
At the moment, it is not possible to allow non-unique user emails. One of the reasons is that User.login supports both email and username, i.e. you can login by entering an email and a password.
请参阅this link .
但是别担心,有一个丑陋的(或者可能是创造性的)方法来解决这个问题:
1.从common/models/base-user.json
中的用户模型扩展:
{
"name": "baseUser",
"base": "User",
"idInjection": true,
"hidden":["email"],
"properties": {
"username": {
"type": "string",
"required": true,
"index": {
"unique": true
}
}
}
}
2.在common/models/base-user.js
中注册之前为每个用户创建随机电子邮件:
module.exports = function (BaseUser) {
BaseUser.beforeRemote('create', function (context, user, next) {
var req = context.req;
req.body.email =Date.now()+"a@b.cc";
next();
});
};
3.定义baseUser模型并在server/config-model.json
中隐藏User模型
"baseUser": {
"dataSource": "MongoDB",
"public": true
},
"User": {
"dataSource": "MongoDB",
"public": false
}
关于node.js - 在strongloop上创建新用户,无需输入电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36276212/