mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Code cleanup.
git-svn-id: http://svn.redmine.org/redmine/trunk@13682 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f1308e64af
commit
62cf53384d
@ -22,7 +22,8 @@ class Token < ActiveRecord::Base
|
|||||||
|
|
||||||
before_create :delete_previous_tokens, :generate_new_token
|
before_create :delete_previous_tokens, :generate_new_token
|
||||||
|
|
||||||
@@validity_time = 1.day
|
cattr_accessor :validity_time
|
||||||
|
self.validity_time = 1.day
|
||||||
|
|
||||||
def generate_new_token
|
def generate_new_token
|
||||||
self.value = Token.generate_token_value
|
self.value = Token.generate_token_value
|
||||||
@ -30,12 +31,12 @@ class Token < ActiveRecord::Base
|
|||||||
|
|
||||||
# Return true if token has expired
|
# Return true if token has expired
|
||||||
def expired?
|
def expired?
|
||||||
return Time.now > self.created_on + @@validity_time
|
return Time.now > self.created_on + self.class.validity_time
|
||||||
end
|
end
|
||||||
|
|
||||||
# Delete all expired tokens
|
# Delete all expired tokens
|
||||||
def self.destroy_expired
|
def self.destroy_expired
|
||||||
Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - @@validity_time]
|
Token.where("action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - validity_time).delete_all
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the active user who owns the key for the given action
|
# Returns the active user who owns the key for the given action
|
||||||
@ -78,7 +79,7 @@ class Token < ActiveRecord::Base
|
|||||||
# Removes obsolete tokens (same user and action)
|
# Removes obsolete tokens (same user and action)
|
||||||
def delete_previous_tokens
|
def delete_previous_tokens
|
||||||
if user
|
if user
|
||||||
Token.delete_all(['user_id = ? AND action = ?', user.id, action])
|
Token.where(:user_id => user.id, :action => action).delete_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user