【问题标题】:Why do Clearance guards check signed_in?为什么清关警卫检查签到?
【发布时间】:2016-05-02 17:01:04
【问题描述】:

通关守卫的示例似乎都检查了signed_in?。这让我感到困惑,因为似乎 signed_in? 不应该设置为 true,直到用户通过了许可守卫。我认为守卫的全部目的是防止登录。

class EmailConfirmationGuard < Clearance::SignInGuard
  def call
    if unconfirmed?
      failure("You must confirm your email address.")
    else
     next_guard
    end
  end

  def unconfirmed?
    signed_in? && !current_user.confirmed_at
  end
end

【问题讨论】:

    标签: ruby-on-rails clearance


    【解决方案1】:

    如果用户是nil,我想不出你为什么要运行保护堆栈的原因,所以我不确定。我认为这可能是实施的意外。

    在创建会话时,我们这样做:

    def create
      @user = authenticate(params)
    
      sign_in(@user) do |status|
        if status.success?
          redirect_back_or url_after_create
        else
          flash.now.notice = status.failure_message
          render template: "sessions/new", status: :unauthorized
        end
      end
    end
    

    如果authenticate 返回nil,我们仍然进入堆栈。我们可能应该考虑不这样做。如果您在 Clearance 存储库本身上打开问题,我们可以将其视为对 Clearance 2.0 的更改

    【讨论】:

      猜你喜欢
      • 2016-04-13
      • 2012-10-21
      • 2017-11-27
      • 2014-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-12
      相关资源
      最近更新 更多