如何使用Devise认证验证注册电子邮件地址是否来自某个域? [英] How can I use Devise Authentication to validate that a sign up email address is from certain domain?
本文介绍了如何使用Devise认证验证注册电子邮件地址是否来自某个域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想确保唯一拥有某个域名的电子邮件地址的人可以注册使用Devise的网站。
例如,使用电子邮件joe@mysite.com,他们应该收到确认电子邮件,但是如果使用joe@yoursite.com注册,他们应该收到一条错误消息。
解决方案
在config / initializers / devise.rb中取消注释此行
#正则表达式用于验证电子邮件地址
#config.email_regexp = / ^([\w\。%\ + \ - ] +)@([\w\ - ] + \。)+( [\w] {2,})$ / i
并将其更改为使用域I想限制到:
config.email_regexp = /\A([\w\.%\++ \\ - ] +)@ mysite\.com\z / i
/ p>
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.
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.
解决方案
Uncommenting this line in 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.
这篇关于如何使用Devise认证验证注册电子邮件地址是否来自某个域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文