node.js - 在strongloop上创建新用户,无需输入电子邮件

标签 node.js authentication loopbackjs strongloop

我们的登录模型仅要求用户输入用户名和密码,电子邮件是可选的,但是环回用户模型需要用户输入电子邮件才能创建新用户。

有没有一种方法可以在 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/

相关文章:

node.js - 使用 IISNode 将使用 Loopback.io 生成的 API 托管到 Azure

loopbackjs - 环回 : How to define ACL rules in a mixin?

loopbackjs - 将内置模型迁移到数据库

node.js - 如何克隆可读流

node.js - 在远程 URL 上重用 Supertest 测试

javascript - Mocha 回调中的断言不起作用

c# - 表单认证

Android AsyncTask 和登录

sql - 从 Node.JS 连接到 SQL Azure

django - Django 是否有内置的登录模板?