|
|
|
@ -12,20 +12,25 @@ class ApplicationController < ActionController::Base
|
|
|
|
|
include WardenAuthentication
|
|
|
|
|
include Pundit
|
|
|
|
|
|
|
|
|
|
def unauthenticated_user
|
|
|
|
|
store_location
|
|
|
|
|
redirect_to new_login_path, notice: "Please log in to proceed"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def unauthenticated_api
|
|
|
|
|
render json: "Unauthenticated", status: 401
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def warden_strategies
|
|
|
|
|
[:auth_cookie]
|
|
|
|
|
def warden_scope
|
|
|
|
|
:user
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def decorated_current_user
|
|
|
|
|
current_user && CurrentUserDecorator.new(current_user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ensure_authenticated!
|
|
|
|
|
handle_unauthenticated unless current_user
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def store_location
|
|
|
|
|
session[:return_to] = request.path
|
|
|
|
|
end
|
|
|
|
@ -52,15 +57,6 @@ class ApplicationController < ActionController::Base
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle_unauthenticated
|
|
|
|
|
if request.xhr?
|
|
|
|
|
render json: "Unauthenticated", status: 401
|
|
|
|
|
else
|
|
|
|
|
store_location
|
|
|
|
|
redirect_to new_login_path, notice: "Please log in to proceed"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle_not_found
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.any do
|
|
|
|
|