]> git.openstreetmap.org Git - rails.git/blob - app/models/oauth_nonce.rb
Update query icon to display cursor with '?'
[rails.git] / app / models / oauth_nonce.rb
1 # == Schema Information
2 #
3 # Table name: oauth_nonces
4 #
5 #  id         :integer          not null, primary key
6 #  nonce      :string
7 #  timestamp  :integer
8 #  created_at :datetime
9 #  updated_at :datetime
10 #
11 # Indexes
12 #
13 #  index_oauth_nonces_on_nonce_and_timestamp  (nonce,timestamp) UNIQUE
14 #
15
16 # Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
17 # Thus you can use the same nonce with a different timestamp and viceversa.
18 class OauthNonce < ActiveRecord::Base
19   validates :timestamp, :presence => true
20   validates :nonce, :presence => true, :uniqueness => { :scope => :timestamp }
21
22   # Remembers a nonce and it's associated timestamp. It returns false if it has already been used
23   def self.remember(nonce, timestamp)
24     return false if Time.now.to_i - timestamp.to_i > 86400
25     oauth_nonce = OauthNonce.create(:nonce => nonce, :timestamp => timestamp.to_i)
26     return false if oauth_nonce.new_record?
27     oauth_nonce
28   end
29 end