ruby-on-railshobo

How do I reset a user password from the console in Hobo/Rails


The rails framework Hobo is brilliant and automatically creates the first user as the admin user (unless you ask it not to). The problem I have is that running rails in development I can't remember what the password was. This should be trivial because I just run rails console, find the user admin = User.find :first and reset the password (trying)

 admin.password = 'Anything1234'
 admin.password_confirmation = admin.password
 admin.save
 >false
 admin.errors
 >{:current_password=>["is not correct"]}

I.e. the implication is that the variable current_password needs to be set correctly before I can change the existing password.

I'm afraid the Hobo documentation doesn't help in this case. Does anyone know the how to drive the Hobo user model to reset the password?


Solution

  • 4 possible solutions:

    1: run your app, and click on the forgot password link. The message will appear in your logs, so you don't need a mailer set up.

    2: Just save without doing any validations:

    admin.save(false)
    

    EDIT: in Rails 3 this is

    admin.save(:validate => false)
    

    3: Another option is just to delete all users so you get your initial user entry screen back.

    4: If you really want to run the validations, you can trigger the request_password_reset lifecycle:

    admin.lifecycle.request_password_reset!(Guest.new)
    

    then look in development log for the reset password key

    u.lifecycle.reset_password!(Guest.new, :key => 'a0a2db1035065fa7ad5d46d35669d206aee73668', :password=>"test123", :password_confirmation=>"test123")