14868

UserSession.find returns nil after changing password

Question:

I recently created a way to change the current user password, however after saving the record, my UserSession.find returns nil, I tried by writing UserSession.new({...}).save with no luck, any suggestion on how to resolve this issue?

Here is my code, notice that is run through an AJAX request (this is a method under UserSessionController):

def

change_my_password #print "--------------RECORD: #{current_user_session.record.as_json}-------- #{current_user_session.user.as_json}" user = current_user user_email = user.email user_remember_me = user.remember_created_at response = { :success => false, :message_code => Extjs::MessageCodes::ERROR, :message => 'Si è verificato un errore', :total => 0, :root => [] } if user.valid_password?(params[:old_password], true) user.password = params[:new_password] user.password_confirmation = params[:confirm_password] response[:message] = 'La nuova password e la conferma non coincidono o sono troppo brevi' if user.save response[:success] = true response[:message_code] = Extjs::MessageCodes::SUCCESS response[:message] = 'Password modificata con successo' end else response[:message] = 'La password precedente non coincide con quella attualmente in uso' end respond_to do |format| format.extjson { render :json => response } end end

Answer1:

Ensure that you haven't set the <a href="https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/acts_as_authentic/session_maintenance.rb#L35" rel="nofollow">maintain_sessions</a> parameter to false, i.e.:

acts_as_authentic do |c| c.maintain_sessions = false # change this to true. end

<strong>OR</strong>

Update the session manually after save:

user.send(:update_sessions)

<strong>OR</strong>

Recreate the session after the save:

UserSession.create(user)

Answer2:

Actually I didn't find a solution to this issue: I solved by forcing a login again after changing password (whcih is even added security, so not that bad).

I think KandadaBoggu is right with his answer, but I tested all of them and they are not working for me.

Maybe it's an issue created by something wrong in my code, I really don't know. At the moment I just consider this as the solution because it's actually working for my software.

If a better answer is found, I would be happy to mark it.

Thanks to everyone.

Recommend

  • IE11 throwing “SCRIPT1014: invalid character” where all other browsers work
  • nonblocking BIO_do_connect blocked when there is no internet connected
  • Get data from AJAX - How to
  • Dynamically accessing properties of knockoutjs observable array
  • HTML download movie download link
  • Bug in WPF DataGrid
  • AES padding and writing the ciphertext to a disk file
  • How to add date and time under each post in guestbook in google app engine
  • Change an a tag attribute in JavaScript based on screen width
  • How to show dropdown in excel using jrxml (jasper api)?
  • Convert array of 8 bytes to signed long in C++
  • Importing jscolor library in angular 2
  • Release, debug version and Authorization Google?
  • jquery mobile loadPage not working
  • Apache 2.4 - remove | delete | uninstall
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Is there a mandatory requirement to switch app.yaml?
  • File upload with ng-file-upload throwing error
  • How to delete a row from a dynamic generate table using jquery?
  • Python: how to group similar lists together in a list of lists?
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#
  • AngularJs get employee from factory
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Free memory of cv::Mat loaded using FileStorage API
  • Trying to get generic when generic is not available
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • How to get Windows thread pool to call class member function?
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?