自定义用户内置模型验证 [英] Customizing User built-in Model validation
问题描述
我正在寻找一种自定义内置用户模型验证的方法.
I'm looking for a way to customize the validation for the built-in User Model.
目标是允许用户使用相同的电子邮件但使用不同的用户名注册一个帐户.
The objective is to be allow users to register an account with the same e-mail but different username.
我尝试覆盖用户模型的设置方法,以防止对email属性的唯一性进行验证,但是不幸的是,这是不可行的.至于钩子,我找不到任何可以满足我需求的东西.
I've tried to override the Setup Method for the User Model to prevent the validation of the uniqueness of the email property, but unfortunately that was a no go. As for hooks, I've couldn't find any to fulfill my needs.
作为参考,验证发生在"loopback/common/models/user.js:556"中:
For reference, the validation occurs in 'loopback/common/models/user.js:556':
if (!(UserModel.settings.realmRequired || UserModel.settings.realmDelimiter)) {
UserModel.validatesUniquenessOf('email', {message: 'Email already exists'});
UserModel.validatesUniquenessOf('username', {message: 'User already exists'});
}
有什么方法可以用来禁用此电子邮件验证?
Is there any way that I can use to disable this e-mail validation?
谢谢.
推荐答案
免责声明:我是LoopBack小组成员.
目前,不允许非唯一用户的电子邮件.原因之一是User.login
支持email
和username
,即您可以通过输入电子邮件和密码来登录.
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.
原则上,可以更改LoopBack以支持您的用例,请打开GitHub问题以讨论可能的实现.
In principle, LoopBack can be changed to support your use case, please open a GitHub issue to discuss a possible implementation.
这篇关于自定义用户内置模型验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!