Devise logging out automatically after password change

后端 未结 9 1816
离开以前
离开以前 2020-12-07 19:53

In Devise, if I change user\'s password and after it gets updated in the db, the site immediately logs out the user. I don\'t want this behavior - how do i do that. please h

相关标签:
9条回答
  • 2020-12-07 20:36

    The example above did not work for me using multiple scopes in Devise.

    I had to add the scope/resource name in the sign_in path for it to work, and to prevent chaos I also had to sign out the old user or else all kinds of confusion would abound.

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

    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 I had to forcibly sign out the user because somewhere I overrode Devise's code in order not to have users sign out during certain actions. In hindsight; not a good idea! This approach is much better! Being that it is safer to make your own Controllers versus overriding Devise's code unless it's absolutely unavoidable.

    0 讨论(0)
  • 2020-12-07 20:39

    Update to Bill Eisenhauer answer above-

    sign_in(current_account, :bypass => true) has been deprecated use bypass_sign_in current_account instead

    More details can be found here http://www.rubydoc.info/github/plataformatec/devise/Devise/Controllers/SignInOut#bypass_sign_in-instance_method

    0 讨论(0)
  • 2020-12-07 20:40

    Add the following piece of code to your method in which you are updating the user's password, right after updating the user's password in the database:

    def update
     . . . . .<your code>
     . . . . .<your code>
    
     sign_in(@user, :bypass => true)
    
     . . . . .<your code>
     . . . . .<your code>
    end
    
    0 讨论(0)
提交回复
热议问题