socialforge/app/models/api_key.rb

22 lines
437 B
Ruby
Raw Normal View History

2014-11-27 19:43:04 +08:00
class ApiKey < ActiveRecord::Base
attr_accessible :access_token, :active, :expires_at, :user_id
before_create :generate_access_token
before_create :set_experation
# validates_presence_of :user_id, :access_token
def expired?
DateTime.now >= self.expires_at
end
private
def generate_access_token
self.access_token = SecureRandom.hex
end
def set_experation
self.expires_at = DateTime.now + 30
end
end