简体   繁体   English

如何使用设计验证来验证注册电子邮件地址是否来自某个域?

[英]How can I use Devise Authentication to validate that a sign up email address is from certain domain?

I would like to make sure the only people with email address of a certain domain can signup for a site that is using Devise. 我想确保只有某个域的电子邮件地址的人可以注册使用Devise的网站。

For instance if people sign-up with the email joe@mysite.com, they should get a confirmation email but if the sign up with joe@yoursite.com, they should get a error message. 例如,如果人们使用电子邮件joe@mysite.com注册,他们应该收到确认电子邮件,但如果使用joe@yoursite.com注册,他们应该收到错误消息。

Uncommenting this line in config/initializers/devise.rb 在config / initializers / devise.rb中取消注释此行

# Regex to use to validate the email address
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i

and changing it to use the domain I wanted to limit to: 并将其更改为使用我想限制的域:

config.email_regexp = /\A([\w\.%\+\-]+)@mysite\.com\z/i

did the trick. 做了伎俩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM