adauth undefined方法`return_and_create_from_adauth'代表

时间:2015-10-28 13:44:39

标签: ruby-on-rails ruby authentication

我正在尝试使用adauth将rails应用程序与活动目录集成。我正在

  

的未定义方法`return_and_create_from_adauth'      

app / controllers / sessions_controller.rb:9:在'create'

class SessionsController < ApplicationController
def new
    redirect_to 'home' if current_user # home was /adauth
end
def create
    ldap_user = Adauth.authenticate(params[:username], params[:password])
    if ldap_user
    #   user = User.return_and_create_with_adauth(ldap_user)
        user = User.return_and_create_from_adauth(ldap_user)
        session[:user_id] = user.id
        redirect_to 'home'
    else
        redirect_to '/sessions/new', :error => "Invalid Login"
    end
end

def destroy
    session[:user_id] = nil
    redirect_to '/sessions/new'
end
end

注意 - 我看到一篇文章说使用create_from_adauth而不是create_with_adauth所以我尝试了两种方式并得到了同样的错误。

请注意 如果我使用良好的活动目录凭据登录,则会收到错误消息。如果我使用错误的活动目录凭据登录,我将被重定向到登录屏幕。这似乎表明问题可能出在用户模型上?

用户架构:

create_table "users", force: :cascade do |t|
t.string   "login"
t.text     "group_strings"
t.string   "name"
t.string   "ou_strings"
t.datetime "created_at",    null: false
t.datetime "updated_at",    null: false
end

服务器日志

Started POST "/adauth" for 127.0.0.1 at 2015-10-28 09:29:00 -0400
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"√",         "authenticity_token"=> j  
REMOVED BY    MEQ==",        
"username"=>"cmendla", "password"=>"[FILTERED]", "commit"=>"Login!"}
Completed 500 Internal Server Error in 12ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `return_and_create_with_adauth' 
for #      <Class:0x5163510>):
 app/controllers/sessions_controller.rb:8:in `create'

我想补充说我遇到匹配线问题,所以我在routes.rb中使用了单独的get / put行。我不确定这可能是一个问题。抛出错误的匹配语句在此处注释掉。

  resources :users
# match \"/adauth\" => \"sessions#create\"
#  match \"/signout\" => \"sessions#destroy\"
get   "/adauth"   => "sessions#create"
 post  "/adauth"   => "sessions#create"
get   "/signout"  => "sessions#destroy"
post  "/signout"  => "sessions#destroy"

#  #match "/signout" => "sessions#destroy, via: [:get, :post]"
#  #match "/adauth" => "sessions#create, via: [:get, :post]"
resources :sessions
#  match "/signout" => "sessions#destroy"
#  match "/adauth" => "sessions#create"
#  resources :sessions
resources :searches
resources :attachments
mount Ckeditor::Engine => '/ckeditor'
resources :documents
resources :reviewers
resources :tags
resources :authors
resources :tags
resources :categories
resources :help_requests


get 'home' => 'home_page#home'
get 'help/uploads' => 'about_and_help#upload_help'
get 'about' => 'about_and_help#about'
get 'attachments' => 'attachments#index'
# get 'login' => 'sessions#create'
# post 'login' => 'sessions#create'
get 'login' => 'sessions#new'
post 'login' => 'sessions#new'

2 个答案:

答案 0 :(得分:2)

您需要将方法名称从return_and_create_with_adauth更改为return_and_create_from_adauth。更正将是:

user = User.return_and_create_from_adauth(ldap_user)

这是新模型的链接:

https://github.com/Arcath/Adauth/blob/master/lib/adauth/rails/model_bridge.rb

答案 1 :(得分:0)

您没有显示您的用户模型。我相信你可能省略了include Adauth::Rails::ModelBridge