summaryrefslogtreecommitdiff
path: root/app/models/token.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/token.rb')
-rw-r--r--app/models/token.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/app/models/token.rb b/app/models/token.rb
index ff2ad12..4afd275 100644
--- a/app/models/token.rb
+++ b/app/models/token.rb
@@ -1,8 +1,15 @@
require 'digest/sha2'
class Token < CouchRest::Model::Base
+ def self.expires_after
+ APP_CONFIG[:auth] && APP_CONFIG[:auth][:token_expires_after]
+ end
- use_database :tokens
+ include CouchRest::Model::Rotation
+ rotate_database :tokens,
+ :every => 1.month,
+ :timestamp_field => :last_seen_at,
+ :timeout => self.expires_after.to_i # in minutes
belongs_to :user
@@ -23,10 +30,6 @@ class Token < CouchRest::Model::Base
self.find Digest::SHA512.hexdigest(token)
end
- def self.expires_after
- APP_CONFIG[:auth] && APP_CONFIG[:auth][:token_expires_after]
- end
-
def self.expired
return [] unless expires_after
by_last_seen_at.endkey(expires_after.minutes.ago)