2013-05-07 79 views
1

我使用Devise進行網站身份驗證。我有我的用戶模型設置如下:在登錄時設計401

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :lockable, :timeoutable and :omniauthable 

    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable, 
     :token_authenticatable, :confirmable 

    attr_accessible :email, :name, :password, :password_confirmation, :remember_me, :college_id, :role 

有以下途徑:

devise_for :users 
    as :user do 
    get 'sign_in'    => 'devise/sessions#new',  :as => :login 
    post 'sign_in'   => 'devise/sessions#create', :as => :user_session 
    delete 'sign_out'   => 'devise/sessions#destroy', :as => :logout 
    get 'signup'    => 'devise/registrations#new', :as => :signup 
    get 'forgot_password'  => 'devise/passwords#new',  :as => :forgot_password 
    get 'resend_confirmation' => 'devise/confirmations#new', :as => :resend_confirmation 
    end 

和我收到以下錯誤:

Started POST "/sign_in" for 127.0.0.1 at 2013-05-06 19:57:34 -0400 
Processing by Devise::SessionsController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"iy0BI3A6zY5TTIJ2eYkOpgwFIFubO2O8wII8GAmjDmE=", "email"=>"[email protected]", "password"=>"[FILTERED]", "x"=>"-630", "y"=>"-434"} 
Completed 401 Unauthorized in 1ms 
Processing by Devise::SessionsController#new as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"iy0BI3A6zY5TTIJ2eYkOpgwFIFubO2O8wII8GAmjDmE=", "email"=>"[email protected]", "password"=>"[FILTERED]", "x"=>"-630", "y"=>"-434"} 

這是顯示在用戶界面上向上作爲「無效的電子郵件或密碼」。但是我確信輸入的密碼是正確的,並且用戶存在於數據庫中(通過控制檯驗證)。設計似乎沒有對數據庫進行任何查詢。這是正常的嗎?

任何想法?所有的幫助表示讚賞。

+0

確保您的設計控制器的定製版本不要求您進行認證。確保它們是原始設計基類的擴展,而不僅僅是'ApplicationController'。它看起來像設置,以便應用程序要求您進行身份驗證才能進行身份驗證。你能告訴我們你的'SessionsController'嗎? – PaReeOhNos 2013-05-07 00:46:13

+0

我沒有自定義的SesssionController,我完全使用Devise控制器。 – NolanDC 2013-05-07 01:40:39

+0

嗯,爲什麼你有'as:用戶做'塊呢?對於普通的老設計,你只需要'devise_for:users'。嘗試評論整個區塊,看看是否有幫助? – PaReeOhNos 2013-05-07 01:41:39

回答

2

嘗試這種在配置/初始化/ devise.rb

config.authentication_keys = [ :email ] 

在user.rb您需要添加attr_accessor爲:密碼未保存到數據庫出於安全原因

attr_accessor :password 
+0

我嘗試在user.rb中添加'attr_accessor:password',這導致我的seed.rb中的用戶無需encrypted_pa​​ssword(空「」,而不是像之前那樣使用散列)來創建。 – NolanDC 2013-05-08 04:10:09

+0

您是否在使用管理員的情況下使用gmail帳戶的用戶名和密碼進行應用程序登錄? – Murhari 2013-05-08 07:44:20

+0

我不確定我是否理解這個問題。我們根本沒有使用Gmail帳戶。 – NolanDC 2013-05-08 17:39:41