Cope with MESSAGES_DOMAIN not being defined
[rails.git] / app / models / oauth_token.rb
index 5fca40ce203e425965a59a222615976cf70eb5e4..c45a3d569e0bdc8f7f2af78c9c7cef5dd0a3c160 100644 (file)
@@ -3,7 +3,17 @@ class OauthToken < ActiveRecord::Base
   belongs_to :user
   validates_uniqueness_of :token
   validates_presence_of :client_application, :token, :secret
   belongs_to :user
   validates_uniqueness_of :token
   validates_presence_of :client_application, :token, :secret
-  before_validation_on_create :generate_keys
+  before_validation :generate_keys, :on => :create
+  
+  def self.find_token(token_key)
+    token = OauthToken.find_by_token(token_key, :include => :client_application)
+    if token && token.authorized?
+      logger.info "Loaded #{token.token} which was authorized by (user_id=#{token.user_id}) on the #{token.authorized_at}"
+      token
+    else
+      nil
+    end
+  end
   
   def invalidated?
     invalidated_at != nil
   
   def invalidated?
     invalidated_at != nil