Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't log in with a valid password using Authlogic and Ruby on Rails?
    text
    copied!<p>We support a bit of an unusual scheme. We don't require a password on User creation, and use password_resets to add a password to the user later, on demand. The problem is, once a password is created, the console indicates the password is valid:</p> <p><code> user.valid_password? 'test'<br> => true</code></p> <p>but in my UserSessions controller, @user_session.save returns false using the same password. What am I not seeing?</p> <p>Kimball</p> <p>UPDATE:</p> <p>Providing more details, here is the output when saving the new password:</p> <p><code>Processing PasswordResetsController#update (for 127.0.0.1 at 2011-01-31 14:01:12) [PUT] Parameters: {"commit"=>"Update password", "action"=>"update", "_method"=>"put", "authenticity_token"=>"PQD4+eIREKBfHR3/fleWuQSEtZd7RIvl7khSYo5eXe0=", "id"=>"v3iWW5eD9P9frbEQDvxp", "controller"=>"password_resets", "user"=>{"password"=>"johnwayne"}}</code></p> <p>The applicable SQL is:</p> <p><code> UPDATE <code>users</code> SET <code>updated_at</code> = '2011-01-31 22:01:12',<br> <code>crypted_password</code> = 'blah',<br> <code>perishable_token</code> = 'blah',<br> <code>password_salt</code> = 'blah',<br> <code>persistence_token</code> = 'blah'<br> WHERE <code>id</code> = 580 <p>I don't see an error per se, @user_session.save just returns false, as if the password didn't match.</p> <p>I skip validating passwords in the User model:</p> <p><code>class User &lt; ActiveRecord::Base<br> acts_as_authentic do |c|<br> c.validate_password_field = false<br> end </code></p> <p>Here's the simplified controller code:</p> <p><code> def create<br> logger.info("SAVED SESSION? #{@user_session.save}")<br> end </code></p> <p>which outputs:</p> <p><code> Processing UserSessionsController#create (for 127.0.0.1 at 2011-01-31 14:16:59) [POST]<br> Parameters: {"commit"=>"Login", "user_session"=>{"remember_me"=>"0", "password"=>"johnwayne", "email"=>"test@email.com"}, "action"=>"create", "authenticity_token"=>"PQD4+eIREKBfHR3/fleWuQSEtZd7RIvl7khSYo5eXe0=", "controller"=>"user_sessions"}<br> User Columns (2.2ms) SHOW FIELDS FROM <code>users</code><br> User Load (3.7ms) SELECT * FROM <code>users</code> WHERE (<code>users</code>.<code>email</code> = 'test@email.com') ORDER BY email ASC LIMIT 1<br> SAVED SESSION? false<br> CACHE (0.0ms) SELECT * FROM <code>users</code> WHERE (<code>users</code>.<code>email</code> = 'test@email.com') ORDER BY email ASC LIMIT 1<br> Redirected to <a href="http://localhost:3000/login" rel="nofollow">http://localhost:3000/login</a> </code></p> <p>Lastly, the console indicates that the new password is valid:</p> <p> $ u.valid_password? 'johnwayne'<br> => true<br> </code></p> <p>Would love to do it all in the console, is there a way to load UserSession controller and call methods directly?</p> <p>Kimball</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload