Method wrapper in plugin only loaded in console but not on server
Added by Alexander J. Murmann almost 15 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 almost 15 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 Alexander J. Murmann almost 15 years ago
Eric Davis gave me helpful advise on stackoverflow.com to solve this: http://stackoverflow.com/questions/2278031/wrapping-class-method-via-alias-method-chain-in-plugin-for-redmine
I also found the following two examples in Plugins from Eric Davis as well, that solved this problem for me:
http://github.com/edavis10/redmine_extra_ldap/blob/707df49063c0ffe67c9a8035920a7e2b75b04dd0/lib/redmine_extra_ldap/patches/auth_source_ldap_patch.rb
http://github.com/edavis10/redmine_extra_ldap/blob/707df49063c0ffe67c9a8035920a7e2b75b04dd0/init.rb
Thank you very much again for your help, Eric!
RE: Method wrapper in plugin only loaded in console but not on server - Added by Eric Davis almost 15 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