Class: Dune::Api::BaseController
- Inherits:
-
ActionController::Metal
- Object
- ActionController::Metal
- Dune::Api::BaseController
show all
- Defined in:
- app/controllers/dune/api/base_controller.rb
Constant Summary
collapse
- MODULES =
[
AbstractController::Rendering,
ActionController::Redirecting,
ActionView::Rendering,
ActionController::Rendering,
ActionController::Renderers::All,
ActionController::ConditionalGet,
ActionController::MimeResponds,
ActionController::ImplicitRender,
ActionController::StrongParameters,
ActionController::ForceSSL,
ActionController::HttpAuthentication::Token::ControllerMethods,
ActionController::Serialization,
ActionController::Instrumentation,
ActionController::ParamsWrapper,
ActionController::Rescue,
HasScope,
Pundit,
Dune::Api::Engine.routes.url_helpers,
Rails.application.routes.url_helpers,
Pundit,
]
Instance Method Summary
collapse
Instance Method Details
#access_token ⇒ Object
45
46
47
|
# File 'app/controllers/dune/api/base_controller.rb', line 45
def access_token
@access_token
end
|
#check_authorization! ⇒ Object
57
58
59
60
61
62
|
# File 'app/controllers/dune/api/base_controller.rb', line 57
def check_authorization!
authenticate_or_request_with_http_token do |token, options|
@access_token = AccessToken.find_by(code: token)
end
@access_token.is_a?(AccessToken) or handle_unauthorized
end
|
#current_user ⇒ Object
49
50
51
|
# File 'app/controllers/dune/api/base_controller.rb', line 49
def current_user
@current_user ||= access_token.user
end
|
#handle_forbidden ⇒ Object
41
42
43
|
# File 'app/controllers/dune/api/base_controller.rb', line 41
def handle_forbidden
head :forbidden
end
|
#handle_unauthorized ⇒ Object
64
65
66
|
# File 'app/controllers/dune/api/base_controller.rb', line 64
def handle_unauthorized
head :unauthorized
end
|
#require_admin! ⇒ Object
53
54
55
|
# File 'app/controllers/dune/api/base_controller.rb', line 53
def require_admin!
handle_unauthorized unless current_user.admin?
end
|