即使设置了allow_unconfirmed_access_for,Devise也不允许未经确认的用户登录? [英] Why won't Devise allow unconfirmed users to login even when allow_unconfirmed_access_for is set?

查看:86
本文介绍了即使设置了allow_unconfirmed_access_for,Devise也不允许未经确认的用户登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个现有的用户群,并且正在添加电子邮件确认。确认是可选的,但将允许附加功能。用户不需要确认。我添加了可确认的模块并运行迁移。确认工作正常。

We have an existing user base and are adding email confirmation. Confirmation is optional, but will allow additional features. Users are not required to confirm. I've added the confirmable module and ran migrations. Confirmation works as advertised.

但是,用户无法登录,因为它们未被确认。所有当前用户都有无确认值,这是我们想要的(用户可以随时返回并确认其电子邮件)。我遵循了所有Devise wiki文章,并在初始化程序中设置了allow_unconfirmed_access_for:

But, users cannot login since they are not confirmed. All current users have nil confirmation values, which is what we want (users can go back and confirm their email at any time). I've followed all the Devise wiki articles and set allow_unconfirmed_access_for in the initializer:

config.allow_unconfirmed_access_for = 10.years 

我也尝试在我们的用户模型中设置它:

I've also tried setting it in our user model as well:

devise :confirmable, allow_unconfirmed_access_for: 10.years

我也试过使用其他值(1.年,500天等)

I've also tried using other values (1.year, 500.days, etc.)

我的SessionsController与Devise的方法没有什么不同(< github上的href =https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb> )

My SessionsController, which does not differ much from Devise's method (here on github)

class Users::SessionsController < Devise::SessionsController
  respond_to :json

  def new
    redirect_to "/#login"
  end

  def create
    resource = warden.authenticate(auth_options)
    if !resource
      render json: {error: "Invalid email or password" }, status: 401 and return
    end

    sign_in(resource_name, resource)
    render "sign_in", formats: [:json], locals: { object: resource }
  end
end

Devise的回应:

Devise's response:

{错误:你必须先确认你的帐户继续。}

{"error":"You have to confirm your account before continuing."}

Devise 2.1.2 with Rails 3.2.9。

Devise 2.1.2 with Rails 3.2.9.

推荐答案

我只需要在我的用户模型中执行此操作,而不是使用allow_unconfirmed_access_for:

I simply needed to do this in my User model, instead of using allow_unconfirmed_access_for:

  protected
    def confirmation_required?
      false
    end

这篇关于即使设置了allow_unconfirmed_access_for,Devise也不允许未经确认的用户登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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