Last active
December 16, 2015 01:09
-
-
Save pi3r/5353199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::V1::BaseController < ActionController::Base | |
include ActionController::HttpAuthentication::Basic | |
protect_from_forgery with: :null_session | |
before_filter :require_current_user | |
respond_to :json | |
rescue_from AccessDenied do |exception| | |
respond_with({ status: 'error', message: exception.message }, status: :forbidden) | |
end | |
protected | |
def require_current_user | |
raise AccessDenied unless current_user | |
end | |
def current_user | |
@current_user ||= begin | |
user, token = user_name_and_password(request) | |
User.where(github_username: user, api_token: token).first | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment