簡體   English   中英

Restful_authentication插件不起作用

[英]Restful_authentication plugin not working

我正在為Ruby on Rails使用restful_authentication插件。 一切似乎都很好,只是似乎根本沒有創建用戶會話。 我有下面的創建方法。 似乎已設置了self.current_user,但從未創建實際會話。 應該在何時以及如何定義current_user_session。 我的應用程序控制器中有該方法,但這總是失敗。

def create
logout_keeping_session!
user = User.authenticate(params[:login], params[:password])
if user
  # Protects against session fixation attacks, causes request forgery
  # protection if user resubmits an earlier form using back
  # button. Uncomment if you understand the tradeoffs.
  # reset_session
  self.current_user = user
  new_cookie_flag = (params[:remember_me] == "1")
  handle_remember_cookie! new_cookie_flag
  redirect_back_or_default('/')
  flash[:notice] = "Logged in successfully"
else
  note_failed_signin
  @login       = params[:login]
  @remember_me = params[:remember_me]
  render :action => 'new'
end

結束

Application_Controller

  def current_user_session
    return @current_user_session if defined?(@current_user_session)
    @current_user_session = UserSession.find
  end

  def current_user
    return @current_user if defined?(@current_user)
    @current_user = current_user_session && current_user_session.user
  end

UserSession模型為空

如果可以避免,請不要使用restful_authentication。 實際上,有許多更好的替代方法是RESTful且維護得更好:

當您說會話時,您實際上是在說會話,還是說這是restful_authentication的魔法?

我曾經使用過restful_authentication,但某些較舊的應用程序仍然可以使用。 但是,他們使用基於cookie的會話管理,而不是用戶會話模型。

您是否正在使用Rails 2.3.5?

我正在使用redirect_to看到此問題,基本上是在重定向之前刪除了添加到會話中的所有變量。

恢復到2.3.4似乎可以解決我的問題,但是關於在Rails 2.3.X中進行會話有些怪異的問題,燈塔上有一個錯誤

對於您來說,這可能不是一個相同的問題,但是我花了幾個小時才能解決我的問題,因此值得進行快速測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM