Rails&设计:要求用户确认电子邮件的特定功能,但允许他们在确认之前登录

时间:2016-08-22 05:17:43

标签: ruby-on-rails devise

用户注册后,我想引导他们访问他们的仪表板。对于完整功能,他们需要确认他们的电子邮件。

现在,当我添加:确认用户模型时,用户无法登录。

如何实现此功能?

3 个答案:

答案 0 :(得分:1)

  1. 只需写入 devise.rb

    即可
    config.allow_unconfirmed_access_for = nil
    
  2. application.rb

    中编写验证
    def is_confirmed?
     if user_signed_in?
        if current_user.confirmed?
           return true
        else
           flash[:notice] = "You are not allow to view this page."
           redirect_to dashboard_path # your dashboard path
        end
     end
    end
    
  3. 控制器

    中使用
    before_action :is_confirmed?, except: [:dashbord]
    

答案 1 :(得分:0)

我认为你可以通过设计和allowing-unconfirmed-access

实现这一目标

只需添加极长的时间段以允许他们登录,然后只检查用户是否已确认电子邮件 - 向他们显示所有仪表板内容,反之亦然。

或者您可以完全跳过:confirmable验证。

希望这有帮助。

答案 2 :(得分:0)

查看此Wiki页面https://github.com/plataformatec/devise/wiki/How-To:-Add-:confirmable-to-Users

#Solution 1 您可以在devise.rb中配置如下内容:

config.allow_unconfirmed_access_for = nil

因此,这意味着用户无需任何确认即可访问,但例如:

config.allow_unconfirmed_access_for = 1.hour

因此他们可以在1小时内无需确认即可访问

#Solution 2

# in User.rb
protected
def confirmation_required?
  false
end

所以现在使用可以访问任何东西而无需确认,但我认为解决方案#1更有效!