Log out automatically after changing password

In development, if I change the user password and after it is updated in db, the site will immediately exit the system. I do not want this behavior - how to do it. please, help.

+69
ruby-on-rails
Nov 24 '10 at 8:29
source share
7 answers

I had the same problem and the following code seems to work for me.

Assume a password controller is set for a one-point route. In addition, suppose the authenticated model is an account. In doing so, you have the following:

def update if current_account.update_with_password(params[:account]) sign_in(current_account, :bypass => true) flash[:notice] = 'Password updated.' redirect_to account_path else render :action => :show end end 

The key component is a call to the sign_in method, which attempts to re-register the account, but bypasses the callbacks of the boss and saves the account in the session.

+122
Feb 01 2018-11-11T00:
source share

The above example did not work for me, using several areas in Devise.

I had to add the domain / resource name in the sign_in path for it to work, and also to prevent chaos, I also had to write out the old user, otherwise all kinds of confusion will abound.

The changes I had to make look something like this using the example above.

 def update if current_account.update_with_password(params[:account]) sign_out(current_account) sign_in(:account, current_account, :bypass => true) flash[:notice] = 'Password updated.' redirect_to account_path else render :action => :show end end 

Edit to add: I believe that I had to force a user to write out, because somewhere I tried the development code so that users do not exit during certain actions. Backdating; not a good idea! This approach is much better! It may be safer to create your own controllers or cancel the development code if this is not absolutely inevitable.

+10
Jul 21 2018-12-12T00:
source share

Use this code to avoid exiting.

 sign_in(current_user, :bypass => true) 
+10
Sep 16
source share

Add the following code to your method in which you update the user password immediately after updating the user password in the database:

 def update . . . . .<your code> . . . . .<your code> sign_in(@user, :bypass => true) . . . . .<your code> . . . . .<your code> end 
+2
Sep 09 '12 at 16:24
source share

You can just set sign_in_after_reset_password to devise.rb

 config.sign_in_after_reset_password = true 
+2
Aug 18 '17 at 12:39 on
source share

For some reason, current_user not equal to @user , although current_user.id is @user.id So I have to use sign_in(@user, :bypass => true) .

+1
Nov 17 '13 at 19:58
source share

Use the registered module, which will give you the opportunity to register and edit user-defined functions.

https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-password

0
May 6 '11 at 4:09
source share



All Articles