Refactor redirect if user is not authorized
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user