Refactor redirect if user is not authorized

This commit is contained in:
Sebastian Serth
2019-01-31 13:06:28 +01:00
parent 4308f0f3cd
commit f7030e3506

View File

@ -21,12 +21,12 @@ class ApplicationController < ActionController::Base
def render_not_authorized def render_not_authorized
respond_to do |format| respond_to do |format|
format.html do format.html do
if request.referrer.present? && request.referrer.include?(request.base_url) # Prevent redirect loop
destination = request.referrer if request.url == request.referrer
redirect_to :root, alert: t('application.not_authorized')
else else
destination = :root redirect_back fallback_location: :root, allow_other_host: false, alert: t('application.not_authorized')
end end
redirect_to(destination, alert: t('application.not_authorized'))
end end
format.json { render json: {error: t('application.not_authorized')}, status: :unauthorized } format.json { render json: {error: t('application.not_authorized')}, status: :unauthorized }
end end