Devise password reset from Rails console

后端 未结 8 963
梦毁少年i
梦毁少年i 2021-01-30 01:38

While running an app how do you select a user by email address and then set the password manually within rails console for Devise?

Also, where would I go to

相关标签:
8条回答
  • 2021-01-30 01:50

    For some reason, (Rails 2.3??)

    user = User.where(:email => email).first
    

    didn't work for me, but

    user = User.find_by_email('user@example.com')
    

    did it.

    0 讨论(0)
  • 2021-01-30 01:51
    # $ rails console production
    u=User.where(:email => 'usermail@gmail.com').first
    u.password='userpassword'
    u.password_confirmation='userpassword'
    u.save!
    
    0 讨论(0)
  • 2021-01-30 01:51
    User.find_by_email('joe@example.com').update_attributes(:password => 'password')
    
    0 讨论(0)
  • 2021-01-30 02:01

    1.Login in to ralis console

    $ sudo bundle exec rails console production
    

    2.Then update the administrator's password

    irb(main):001:0> user = User.where("username = 'root'")
    irb(main):002:0> u = user.first
    irb(main):003:0> u.password="root2014@Robin"
    => "root2014@Robin"
    irb(main):004:0> u.password_confirmation="root2014@Robin"
    => "root2014@Robin"
    irb(main):005:0> u.save
    => true
    irb(main):006:0> exit
    

    3.Refresh the login page, use the new password to login, enjoy!

    Good Luck!

    0 讨论(0)
  • 2021-01-30 02:02

    If you run the following in the rails console it should do the trick:

    User.find_by(email: 'user_email_address').reset_password!('new_password','new_password')
    

    http://www.rubydoc.info/github/plataformatec/devise/Devise/Models/Recoverable

    0 讨论(0)
  • 2021-01-30 02:05

    You can simply update password field, no need for confirmation password, devise will save it in encrypted form

    u = User.find_by_email('user@example.com')
    u.update_attribute(:password, '123123')
    
    0 讨论(0)
提交回复
热议问题