Reinvent Rails Confirm: Allow first entry at check-in

I am using devise 3.0.3

I have a verified model.

I would like the user to be signed first by registering throughout the session, and then when the user returns, he needs to be confirmed. The idea is not to disrupt the flow of navigation for registration by checking emails.

Another option is to provide the user with a 24-hour delay before rejecting it from entering the system.

I tried using after_inactive_sign_up_path_for as follows:

  def after_inactive_sign_up_path_for(user) user.confirm! sign_in(:user, user) user.confirmed_at = nil user.save return user_path(user) end 

but I still refuse in the end.

Any suggestion doing this right?

+4
source share
1 answer

Good question.

In your user model add this class method

 class User < ActiveRecord::Base def self.allow_unconfirmed_access_for 1.day # Or any time frame you like end end 

In Devise::Models::Confrimable there is a method called confirmation_period_valid? . This method checks the above class method, which by default does not exist and expects nil.

If you set this time, Devise will allow this user to subscribe during this period, even if it is not verified.

You do not need changes on the controller.

Disclaimer: I have not used this solution before, but just finished it by looking at the source code. Theoretically, it should work.

+3
source

Source: https://habr.com/ru/post/1501882/


All Articles