2016-07-27 15 views
2

我使用的是Rails 4.2.1和Devise和rails_admin,我對Rails很陌生。添加身份驗證到我的網站的Rails管理員部分

我在項目中有一個用戶模型和用戶的登錄模塊。但我需要添加Rails管理員身份驗證。我爲此增加了一個新型號Admin。我已經爲Rails Admin登錄設置了基本身份驗證。但現在我需要刪除基本認證併爲Rails Admin添加登錄頁面。我必須做些什麼改變?

至於我的代碼,我目前使用這個基本身份驗證:

RailsAdmin.config do |config| 
    config.authenticate_with do 
    authenticate_or_request_with_http_basic('Site Message') do |username, password| 
     authenticate_admin username, password 
    end 
    end 
end 

我已經加入authenticate_adminapplication_controller的方法,我想使用的身份驗證。

+0

請添加一些代碼片段,它會更容易爲人們提供幫助。 – Maverick

+1

RailsAdmin.config do | config | config.authenticate_with do authenticate_or_request_with_http_basic('Site Message')do | username,password | authenticate_admin用戶名,密碼 結束 結束 結束 – Sachin

+0

現在,我正在使用此進行基本身份驗證。我在application_controller中添加了authenticate_admin方法進行身份驗證 – Sachin

回答

0

由於您正在使用rails管理員的設備,您可以使用設計進行身份驗證。

在你rails_admin.rb添加以下代碼:

config.authenticate_with do 
     warden.authenticate! scope: :user 
    end 
    config.current_user_method(&:current_user)