如何使用设计身份验证来验证注册电子邮件地址是否来自某个域? [英] How can I use Devise Authentication to validate that a sign up email address is from certain domain?
本文介绍了如何使用设计身份验证来验证注册电子邮件地址是否来自某个域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想确保只有拥有某个域的电子邮件地址的人才能注册使用 Devise 的网站.
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.
例如,如果人们使用电子邮件 joe@mysite.com 进行注册,他们应该会收到一封确认电子邮件,但如果人们使用 joe@yoursite.com 进行注册,他们应该会收到一条错误消息.
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.
推荐答案
在 config/initializers/devise.rb 中取消注释这一行
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.comz/i
成功了.
这篇关于如何使用设计身份验证来验证注册电子邮件地址是否来自某个域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文