Beta(白名单)电子邮件列表,用于在Devise上注册 [英] Beta (Whitelisted) Email List for Registration on Devise

查看:86
本文介绍了Beta(白名单)电子邮件列表,用于在Devise上注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Devise,我试图建立一个要求,即只有我白名单中包含的电子邮件才能真正注册。

I'm Using Devise and i'm trying to build a requirement that only emails that are included in my white list can actually Sign Up.

超时电子邮件将被添加到该列表。这意味着今天有10封电子邮件,明天又有20封以上。

Over Time emails will be added to that list. Meaning that Today there are 10 emails, tomorrow another 20+.

但是我还不知道如何实现这一目标。

But i don't know quite yet how to achieve this.

我知道我必须创建我自己的注册控制器,对于验证,我认为我需要类似的东西对此:

I know that i have to Create my own Registrations Controller, and for the Validation i think i need something similar to this:

before_validation :whitelisted?

def whitelisted?
  unless WhiteList.exists?(:email => email)
    errors.add :email, "is not on our beta list"  
  end
end 

但是,对于如何开始或继续执行此操作我一无所知。我什至不知道这是否是最佳实践。

However, i am clueless on how to start or continue this. I don't even know if that's the best Practice.

我如何向该白名单中添加电子邮件,甚至该白名单在哪里?

How do i add emails to that whitelist and where is even that whitelist?

如果某人对新手足够友好,可以向我解释一下。

If someone could be noob-friendly enough to explain this to me.

推荐答案

请尝试以下操作认为这会对您有所帮助。

Try the following i think this could help you.

创建新注册控制人

class RegistrationsController < Devise::RegistrationsController

  def create
    unless WhiteList.exists?(:email => params[:user][:email])
      errors.add :email, "is not on our beta list"
    else
      super  
    end
  end
end

并在 routes文件中用以下内容替换现有文件

and in routes file replace existing with following

devise_for :users, controllers: { registrations: "registrations" }

使用以下方法创建新模型WhiteList

Create new model WhiteList using following

rails g model whitelist email:string

并运行 rake db:migrate 命令。

在此开始之后 Rails控制台使用以下命令添加电子邮件。

after this start Rails console add email's using following command.

Whitelist.create(email: "test@user.com")

这篇关于Beta(白名单)电子邮件列表,用于在Devise上注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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