设计 - 将authentication_keys更改为:从restful_authentication升级后登录 - 无效的电子邮件或密码错误

时间:2011-11-10 18:48:07

标签: ruby-on-rails devise

我最近将我的Rails应用程序从restful_authentication升级为devise,默认情况下,设计登录页面工作(使用电子邮件进行身份验证)。我不希望通过电子邮件进行身份验证,当我在用户模型的“登录”字段上移动身份验证时,它不再有效,我收到以下错误:

  

电子邮件或密码无效。

Devise.rb

config.authentication_keys = [ :login ]

User.rb

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable, :trackable,
         :encryptable, :encryptor => :restful_authentication_sha1
  attr_accessible :login, :email, :password, :password_confirmation, :remember_me, :twitter_name, :twitter_id, :atoken, :asecret

new.haml(for session)

  = form_tag session_path, :class => 'enter_form' do
    %label.form_label_small{:for => "login", :style => "color: #336699"} username
    %br/
    = text_field_tag 'login', @login, :class => 'input_style_state', :style => 'width: 250px;'
    .clear{:style => 'height: 4px'}
    %label.form_label_small{:for => "password", :style => "color: #336699"} password
    %br/
    = password_field_tag 'password', nil, :style => 'width: 250px;'
    .clear{:style => 'height: 4px'}
    %p{:style => "padding: 0; margin:0;"}
      = check_box_tag 'remember_me', '1', @remember_me, :style => 'padding: 0; margin: 0; border: 0'
      = label_tag 'remember_me', 'remember me'
    .clear{:style => "height: 8px"} 
    %a.button.submit_form{:href => '/login'}
      %span{:style => 'width: 40px'}
        login

我和另一个项目有类似的问题。我想如果:登录成功获取身份验证密钥,错误消息会说“无效登录或passowrd”而不是“无效的电子邮件或密码”

关于如何追捕此事的任何想法?我的错误日志没有说什么。这是日志:

Started POST "/users/sign_in" for 127.0.0.1 at Thu Nov 10 13:46:13 -0500 2011
  Processing by Devise::SessionsController#create as HTML
  Parameters: {"authenticity_token"=>"AMole3YOhXPuOQGX27W1Mr7c18XR1Xk9DUF6JvstbZA=", "utf8"=>"✓", "user"=>{"remember_me"=>"0", "login"=>"aressidi", "password"=>"[FILTERED]"}}
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`login` = 'aressidi' LIMIT 1
  NavAd Load (0.3ms)  SELECT `nav_ads`.* FROM `nav_ads`
Completed   in 34ms
  Processing by Devise::SessionsController#new as HTML
  Parameters: {"authenticity_token"=>"AMole3YOhXPuOQGX27W1Mr7c18XR1Xk9DUF6JvstbZA=", "utf8"=>"✓", "user"=>{"remember_me"=>"0", "login"=>"aressidi", "password"=>"[FILTERED]"}}

1 个答案:

答案 0 :(得分:1)

设计错误消息不是动态生成的,因此错误消息并不一定表明它正在查看错误的字段以进行身份​​验证。见http://asciicasts.com/episodes/210-customizing-devise

另请注意您正在使用的ruby版本。 Devise似乎没有使用Ruby 1.9.3正确使用它的config.authentication_keys设置。一旦我切换回Ruby 1.9.2,它就立即开始工作。