Undelete act_as_paranoid deleted user on devise

I have a Rails 3.1.3 application that uses devise to authenticate users and software - removes them with acts_as_paranoid . I want the accounts to be restored during password recovery, user subscription and login, so if they provide a deleted email, I grab this account, make it live again, and then proceed (password recovery or login )

But in the Users::SessionsController#create action, after deleting the user, he receives an Unauthorized error (but now the user should be visible). The code:

 def create # Take into account acts_as_paranoid deleted users resource = resource_class.only_deleted.find_by_email(params[resource_name][:email]) resource.undelete! if resource resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new") set_flash_message(:notice, :signed_in) if is_navigational_format? sign_in(resource_name, resource) respond_with resource, :location => after_sign_in_path_for(resource) end 

If I add a call to resource.reload after deletion, it will not change anything. And if I log into the system again, the user will be properly signed, as he was restored in a previous attempt.

Why is this happening? How can I restore it and register in a single create call?

+3
ruby devise warden acts-as-paranoid
Jan 16 2018-12-21T00:
source share
1 answer

Solved it with the following code snippet:

 def create # Take into account acts_as_paranoid deleted users if (resource = resource_class.only_deleted.find_by_email(params[resource_name][:email])) resource.undelete! # Copied from Warden::Strategies database_authenticatable: sign_in resource if resource.valid_password?(params[resource_name][:password]) end super end 
+5
Mar 23 '12 at 19:50
source share
β€” -



All Articles