Project

General

Profile

Method wrapper in plugin only loaded in console but not on server

Added by Alexander J. Murmann about 14 years ago

I started work on a plugin that allows the administrator to limit the number of allowed login attempts before an account gets locked.

For this I wrote a wrapper for User.try_to_login
What's there so far works all fine with ./script/console but not if I run the project in Mongrel.

My plugin can be found at http://github.com/ajmurmann/Redmine-Login-Attempt-Limiter-plugin
The wrapper itself is here: http://github.com/ajmurmann/Redmine-Login-Attempt-Limiter-plugin/blob/master/lib/user_login_attempt_limiter_patch.rb

Any ideas what might be wrong are highly appreciated!

Thank you very much!


Replies (3)

RE: Method wrapper in plugin only loaded in console but not on server - Added by Alexander J. Murmann about 14 years ago

I again made sure that try_to_login is called and it is. However, via the browser the wrapper I wrote using an alias_method chain is not being called. In the console still everything seems fine.

Could this have something to do with the fact that I wrapping a class method?

Here the relevant code snippet from my module in a simplified form:

require_dependency 'principal'
require_dependency 'user'
require 'login_attempt_count'

module UserLoginAttemptLimiterPatch

  def self.included(base)
    base.extend ClassMethods
    base.class_eval do
      class << self
        alias_method_chain :try_to_login, :attempt_limit
      end
    end
  end

  module ClassMethods
    def try_to_login_with_attempt_limit(login, password)

      user = try_to_login_without_attempt_limit login, password      

      #stuff here gets called via console but not via browser

      user
    end

    def authentication_failed(login)     
      #important code here
      end      

  end
end

User.send(:include, UserLoginAttemptLimiterPatch)

The module this code is in, is required in the init.rb

Thanks again for any help! This problem is driving me nuts. If it at least wouldn't work in the console either...

RE: Method wrapper in plugin only loaded in console but not on server - Added by Eric Davis about 14 years ago

Great, I'm happy that worked for you. I don't normally look on stackoverflow but that question came across my Twitter search before I saw your post in here.

Eric Davis

    (1-3/3)