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

前端 未结 3 1020
时光取名叫无心
时光取名叫无心 2020-12-15 08:21

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 ad

3条回答
  •  太阳男子
    2020-12-15 08:48

    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.

提交回复
热议问题