用设计白名单

我正在使用设计来管理我的rails应用程序中的用户身份validation。 设计真的很棒。

但是我对我的应用程序有特殊要求:用户必须先列入白名单才能注册为用户。

因此,有一个管理员可以创建允许的电子邮件列表。 用户使用电子邮件注册,如果电子邮件位于白名单表中,则他将被注册。 但是,如果邮件不在白名单中,则应使用“您尚未被邀请”之类的消息中止注册。

你知道如何用设计解决这个问题吗?

提前致谢。

你可以做的是创建自己的注册控制器并扩展设备,如:

class MyRegistrationController < Devise::RegistrationsController def create # do your checks super end end 

请参阅: https : //github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb和: https : //github.com/plataformatec/devise/wiki/How-to : -Customize-路由到用户登记的页面

祝好运!

我只想使用模型validation。 我假设你的User类有设计方法

 class User < ActiveRecord::Base devise :database_authenticatable, :registerable #etc before_validation :whitelisted def whitelisted unless celebrityemail.include? email errors.add :email, "#{email} is not on our invitation list" end end end 

我按照建议创建了自己的控制器:

 class Users::RegistrationsController < Devise::RegistrationsController def create email = params[:user][:email] if Admin::Whitelist.find_by_email(email) != nil super else build_resource set_flash_message :error, "You are not permitted to sign up yet. If you have already payed your registration fee, try again later." render_with_scope :new end end end 

我把它放在app/users/registrations_controller.rb 。 然后我不得不将设计注册视图复制到app/views/users/registrations因为没有使用默认视图。

它现在正在工作,谢谢你的帮助