0

我已经在我的 Rails 4 应用程序中实现了 Authlogic。我可以连接到我的 LDAP 服务器并使用我的 AD 用户名和密码进行身份验证。但是,我不能在应用程序的任何地方调用“current_user”。

例如,当我打电话 Welcome, <%= current_user.first_name %>

我得到: undefined method 'first_name' for nil:NilClass

class ApplicationController < ActionController::Base

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.

  helper :all
  protect_from_forgery with: :exception


  helper_method :current_user_session, :current_user

  private
    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

end

任何想法表示赞赏。谢谢!凯蒂

4

4 回答 4

3

Authlogic 正在为我的 Rails 4 应用程序工作。current_user 工作得很好。您可能想再试一次。

于 2013-07-14T16:13:59.177 回答
2

Authlogic 现在正在工作。如果有问题,请在您的 gemfile 中提供以下内容:

gem 'authlogic',github:'binarylogic/authlogic',参考:'e4b2990d6282f3f7b50249b4f639631aef68b939'

于 2013-10-18T20:37:12.520 回答
0

@rhuppert,那个特定的 authlogic 提交真的救了我的培根,谢谢你分享这些信息。结果发现较新的 Authlogic 版本 3.3.0 和 3.4.0 不再适用于我的 Rails 4.0.x 应用程序之一,但是当我使用您提到的版本时(gem 'authlogic', github: 'binarylogic/authlogic',参考:'e4b2990d6282f3f7b50249b4f639631aef68b939')它适用于 Rails 4.0.x。我在 Authlogic 3.4.0 和 3.8.0 中遇到的错误是(来自 Rails 记录器的行):

F, [2014-03-04T07:25:09.640105 #28602] FATAL -- : NameError (uninitialized constant SCrypt):
  app/controllers/user_sessions_controller.rb:15:in `create'

再次感谢!

于 2014-03-04T07:42:36.973 回答
0

到目前为止,Authlogic 还没有为 Rails 4 做好准备:

http://ready4rails4.net/

名称:authlogic
状态:未准备好
注释: 拉取请求

于 2013-07-11T18:28:49.213 回答