简体   繁体   English

Restful_authentication插件不起作用

[英]Restful_authentication plugin not working

I'm using restful_authentication plugin for Ruby on Rails. 我正在为Ruby on Rails使用restful_authentication插件。 All seems fine except that it seems the user session is not getting created at all. 一切似乎都很好,只是似乎根本没有创建用户会话。 I have the create method below. 我有下面的创建方法。 It appears that the self.current_user is being set but that the actual session is never created. 似乎已设置了self.current_user,但从未创建实际会话。 When and how is the current_user_session supposed to be defined. 应该在何时以及如何定义current_user_session。 I have the method in my application controller but this is where it always fails. 我的应用程序控制器中有该方法,但这总是失败。

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

end 结束

Application_Controller 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 model is empty UserSession模型为空

Do not use restful_authentication if you can avoid it. 如果可以避免,请不要使用restful_authentication。 There are a number of better alternatives out there that are actually RESTful and better maintained: 实际上,有许多更好的替代方法是RESTful且维护得更好:

When you say session, do you actually mean a session or is this some restful_authentication magic? 当您说会话时,您实际上是在说会话,还是说这是restful_authentication的魔法?

I used to use restful_authentication, and some older apps still do. 我曾经使用过restful_authentication,但某些较旧的应用程序仍然可以使用。 However, they used cookie-based session management and not a user session model. 但是,他们使用基于cookie的会话管理,而不是用户会话模型。

Are you using rails 2.3.5? 您是否正在使用Rails 2.3.5?

I am seeing issues with this using redirect_to, basically removing any variables added to the session before the redirecting. 我正在使用redirect_to看到此问题,基本上是在重定向之前删除了添加到会话中的所有变量。

Reverting to 2.3.4 seems to of solved my problem, but there is a bug on lighthouse in regards to some weirdness to session in rails 2.3.X 恢复到2.3.4似乎可以解决我的问题,但是关于在Rails 2.3.X中进行会话有些怪异的问题,灯塔上有一个错误

This may not be same issue for you, but has taken me hours to realise a revert fixed my issue, so might be worth a quick test. 对于您来说,这可能不是一个相同的问题,但是我花了几个小时才能解决我的问题,因此值得进行快速测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM