Customizing User built-in Model validation

女生的网名这么多〃 提交于 2019-12-10 11:54:20

问题


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.

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.

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?

Thanks in advance.


回答1:


Disclaimer: I am a LoopBack team member.

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.

In principle, LoopBack can be changed to support your use case, please open a GitHub issue to discuss a possible implementation.



来源:https://stackoverflow.com/questions/26740503/customizing-user-built-in-model-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!