cartodb-4.29/app/models/access_token.rb
2020-06-15 10:58:47 +08:00

39 lines
877 B
Ruby

class AccessToken < OauthToken
def before_create
self.authorized_at = Time.now
self.created_at = Time.now
super
end
def before_save
self.updated_at = Time.now
super
end
def after_create
store_api_credentials
end
def after_destroy
$api_credentials.del metadata_key
super
end
def store_api_credentials
$api_credentials.hset metadata_key, "consumer_key", client_application.key
$api_credentials.hset metadata_key, "consumer_secret", client_application.secret
$api_credentials.hset metadata_key, "access_token_token", token
$api_credentials.hset metadata_key, "access_token_secret", secret
$api_credentials.hset metadata_key, "user_id", user_id
$api_credentials.hset metadata_key, "time", authorized_at
end
private
def metadata_key
"rails:oauth_access_tokens:#{token}"
end
end