白名单与设计 [英] Whitelisting with devise

查看:37
本文介绍了白名单与设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 devise 在我的 rails 应用程序中管理用户身份验证.Devise 非常适合这一点.

I am using devise to manage user authentication in my rails app. Devise is really great for that.

但是我对我的应用程序有一个特殊要求:用户必须先加入白名单,然后才能注册为用户.

However I have a special requirement for my application: A user must be whitelisted before he can register as a User.

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

So there is a admin which creates a list of allowed emails. A user registers with a email and if the email is in the whitelist table he will be registered. If however, the mail is not in the whitelist, the registration should be aborted with a message like "You are not yet invited".

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

Do you have an idea how that could be solved with devise?

提前致谢.

推荐答案

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

What you can do is create your own registrations controller and extend the device one like:

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-routes-to-user-registration-pages

祝你好运!

这篇关于白名单与设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆