##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r13300:62cf53384d78
parent child
Show More
@@ -22,7 +22,8 class Token < ActiveRecord::Base
22 22
23 23 before_create :delete_previous_tokens, :generate_new_token
24 24
25 @@validity_time = 1.day
25 cattr_accessor :validity_time
26 self.validity_time = 1.day
26 27
27 28 def generate_new_token
28 29 self.value = Token.generate_token_value
@@ -30,12 +31,12 class Token < ActiveRecord::Base
30 31
31 32 # Return true if token has expired
32 33 def expired?
33 return Time.now > self.created_on + @@validity_time
34 return Time.now > self.created_on + self.class.validity_time
34 35 end
35 36
36 37 # Delete all expired tokens
37 38 def self.destroy_expired
38 Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - @@validity_time]
39 Token.where("action NOT IN (?) AND created_on < ?", ['feeds', 'api'], Time.now - validity_time).delete_all
39 40 end
40 41
41 42 # Returns the active user who owns the key for the given action
@@ -78,7 +79,7 class Token < ActiveRecord::Base
78 79 # Removes obsolete tokens (same user and action)
79 80 def delete_previous_tokens
80 81 if user
81 Token.delete_all(['user_id = ? AND action = ?', user.id, action])
82 Token.where(:user_id => user.id, :action => action).delete_all
82 83 end
83 84 end
84 85 end
General Comments 0
You need to be logged in to leave comments. Login now