Guest User

Untitled

a guest
Oct 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. class Api::V1::ApplicationController < ActionController::API
  2. include ActionController::HttpAuthentication::Token::ControllerMethods
  3.  
  4. attr_reader :current_user
  5.  
  6. before_filter :require_access_key
  7. before_filter :update_limit
  8.  
  9. private
  10.  
  11. def require_access_key
  12. authenticate_with_http_token do |key, options|
  13. @current_user = Token.find_by_key(key).account if Token.exists?(key: key)
  14. end
  15. end
  16.  
  17. def update_limit
  18. access_token = @current_user.access_token
  19. previous_limit = access_token.limit
  20. access_token.update_attributes limit: previous_limit - 1
  21. end
  22. end
Add Comment
Please, Sign In to add comment