You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
457 B
24 lines
457 B
class ApiKey < ActiveRecord::Base
|
|
attr_accessible :access_token, :active, :expires_at, :user_id
|
|
before_create :generate_access_token
|
|
before_create :set_experation
|
|
|
|
belongs_to :user
|
|
|
|
# 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
|