]> git.openstreetmap.org Git - rails.git/blob - app/models/oauth_nonce.rb
Set font on title
[rails.git] / app / models / oauth_nonce.rb
1 # Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
2 # Thus you can use the same nonce with a different timestamp and viceversa.
3 class OauthNonce < ActiveRecord::Base
4   validates :timestamp, :presence => true
5   validates :nonce, :presence => true, :uniqueness => { :scope => :timestamp }
6
7   # Remembers a nonce and it's associated timestamp. It returns false if it has already been used
8   def self.remember(nonce, timestamp)
9     return false if Time.now.to_i - timestamp.to_i > 86400
10     oauth_nonce = OauthNonce.create(:nonce => nonce, :timestamp => timestamp.to_i)
11     return false if oauth_nonce.new_record?
12     oauth_nonce
13   end
14 end