Automatically log in after confirmation with

I use ready-made confirmation. I have some custom things that I need to override from development. method, so in my user model, I have the following method that overrides it:

def confirm! super gb = Gibbon::API.new(ENV['MAILCHIMP_API_KEY']) gb.lists.subscribe({:id => ENV['MAILCHIMP_ID'], :email => {:email => self.email }}) end 

It works great. Now I'm trying to use it so that the user automatically subscribes after confirmation, but cannot figure out how to do this. I know this is considered a security flaw, but I have weighed the risks and it is worth it to work on my site. I don't want to do anything with the routes file because this method already works, so I should be able to do it from here. I tried putting the following into my configuration file:

 config.allow_insecure_sign_in_after_confirmation = true 

but he does not sign the user.

I looked at the Avoid login after you confirmed that click the link using devem gem? , and this does not help, please do not mark it as a duplicate.

Thanks to everyone.

+9
source share
2 answers

You would change route.rb and controllers / users / translations_controller.rb (maybe the default path)

route.rb to display users / confrimations_controller

 devise_for :users, controllers: {confirmations: 'users/confirmations'} 

Controller Confirmation for automatic login and redirection to

 def after_confirmation_path_for(resource_name, resource) sign_in(resource) any_path # redirect_to is not necessary end 
+18
source

Generate a controller:

 rails generate devise:controllers users -c=confirmations 

Then rewrite the show method:

  # app/controllers/users/confirmations_controller.rb def show super do sign_in(resource) if resource.errors.empty? end end def after_confirmation_path_for(resource_name, resource) after_sign_in_path_for(resource) end 
0
source

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


All Articles