ruby-on-rails - 无法使用 Authlogic 和 Ruby on Rails 使用有效密码登录?

标签 ruby-on-rails ruby authlogic

我们支持一些不寻常的方案。我们在创建用户时不需要密码,并在以后根据需要使用password_resets 为用户添加密码。问题是,一旦创建密码,控制台就会指示密码有效:

user.valid_password? 'test'<br/> => true

但在我的 UserSessions Controller 中,@user_session.save 使用相同的密码返回 false。我没看到什么?

金博尔

更新:

提供更多详细信息,以下是保存新密码时的输出:

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"}}

适用的SQL是:

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

I don't see an error per se, @user_session.save just returns false, as if the password didn't match.

<p>I skip validating passwords in the User model:</p> <p><code>class User < 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"=>"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="077362747347626a666e6b2964686a" rel="noreferrer noopener nofollow">[email protected]</a>"}, "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> = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a7e6f797e4a6f676b636624696567" rel="noreferrer noopener nofollow">[email protected]</a>') 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> = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="532736202713363e323a3f7d303c3e" rel="noreferrer noopener nofollow">[email protected]</a>') ORDER BY email ASC LIMIT 1<br/> Redirected to <a href="http://localhost:3000/login" rel="noreferrer noopener nofollow">http://localhost:3000/login</a> </code></p> <p>Lastly, the console indicates that the new password is valid:</p>

$ u.valid_password? 'johnwayne'<br/> => true<br/>

想要在控制台中完成这一切,有没有办法加载 UserSession Controller 并直接调用方法?

金博尔

最佳答案

在您要保存的对象上,在保存后调用 u.errors.full_messages.inspect 其输出是什么。你也有效吗?

关于ruby-on-rails - 无法使用 Authlogic 和 Ruby on Rails 使用有效密码登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4856382/

相关文章:

ruby-on-rails - 如何使 bundler 再次为非 root 用户工作? (错误地使用root后)

ruby-on-rails - Rails 和 Authlogic : Allow only one session per user?

ldap - 使用 authlogic 和 LDAP 身份验证时如何使密码可选?

ruby-on-rails - Ruby on Rails 登录系统的简史是什么?

ruby-on-rails - 如何一次为所有类变量制作 'attr_reader' 或 'attr_writer'?

ruby - 有没有办法在 Ruby 中获取所有变量?

ruby-on-rails - 如何转义 yield 返回的值

ruby-on-rails - 从Ruby中的CSV转义逗号

ruby-on-rails - current_user 的 Rails 关联

ruby-on-rails - 用于测试 Ruby Gem 的嵌套项目