Why won't Devise allow unconfirmed users to login even when allow_unconfirmed_access_for is set?

半腔热情 提交于 2019-11-25 15:17:46

The Devise team have released a version (2.2.4) that supports nil as a valid value for allow_unconfirmed_access_for, meaning no limit. Issue: https://github.com/plataformatec/devise/issues/2275

You can now do:

config.allow_unconfirmed_access_for = nil 

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

  protected
    def confirmation_required?
      false
    end

I've got the same issue: after turning on devise confirmations previously created accounts are unable to login.

The reason is here:

def confirmation_period_valid?
  self.class.allow_unconfirmed_access_for.nil? || (confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago)
end

Old accounts have confirmation_sent_at set to nil, that's why they are unable to log in.

One solution is to force confirmation_sent_at like that:

update users set confirmation_sent_at=created_at where confirmation_sent_at is NULL;

You can do it manually, or create a migration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!