]> git.openstreetmap.org Git - rails.git/blob - app/models/oauth_token.rb
Show a message when no features are found
[rails.git] / app / models / oauth_token.rb
1 class OauthToken < ActiveRecord::Base
2   belongs_to :client_application
3   belongs_to :user
4
5   scope :authorized, -> { where("authorized_at IS NOT NULL and invalidated_at IS NULL") }
6
7   validates_uniqueness_of :token
8   validates_presence_of :client_application, :token
9
10   before_validation :generate_keys, :on => :create
11   
12   def invalidated?
13     invalidated_at != nil
14   end
15   
16   def invalidate!
17     update_attributes(:invalidated_at => Time.now)
18   end
19   
20   def authorized?
21     authorized_at != nil && !invalidated?
22   end
23   
24   def to_query
25     "oauth_token=#{token}&oauth_token_secret=#{secret}"
26   end
27     
28 protected
29   
30   def generate_keys
31     self.token = OAuth::Helper.generate_key(40)[0,40]
32     self.secret = OAuth::Helper.generate_key(40)[0,40]
33   end
34 end