diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-02-02 08:46:58 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-02-02 08:46:58 +0000 |
commit | 9e0723c11b929ebe53f897d18a25466b8b80849a (patch) | |
tree | 4cad57476950f57615636c0d43f4013b52475e8f /app/models/token.rb | |
parent | 8b010e85e362245eece363682895fa0c445dc83b (diff) | |
download | redmine-9e0723c11b929ebe53f897d18a25466b8b80849a.tar.gz redmine-9e0723c11b929ebe53f897d18a25466b8b80849a.zip |
Refactors methods for searching a user by token.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11296 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/token.rb')
-rw-r--r-- | app/models/token.rb | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/models/token.rb b/app/models/token.rb index 1627b7587..c14175ea8 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -37,11 +37,26 @@ class Token < ActiveRecord::Base Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - @@validity_time] end -private + # Returns the active user who owns the key for the given action + def self.find_active_user(action, key, validity_days=nil) + action = action.to_s + key = key.to_s + return nil unless action.present? && key =~ /\A[a-f0-9]+\z/ + + token = find_by_action_and_value(action, key) + if token && token.user && token.user.active? + if validity_days.nil? || (token.created_on > validity_days.ago) + token.user + end + end + end + def self.generate_token_value Redmine::Utils.random_hex(20) end + private + # Removes obsolete tokens (same user and action) def delete_previous_tokens if user |