mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Improve ip whitelist #2713
This commit is contained in:
parent
afb3d7ed1d
commit
a4ccc5749e
6 changed files with 19 additions and 13 deletions
|
@ -47,16 +47,6 @@ class Registrar::SessionsController < Devise::SessionsController
|
|||
end
|
||||
end
|
||||
|
||||
unless @api_user.registrar.registrar_ip_white?(request.ip)
|
||||
@depp_user.errors.add(:base, I18n.t(:ip_is_not_whitelisted))
|
||||
end
|
||||
|
||||
if @api_user.can_make_api_calls?
|
||||
unless @api_user.registrar.api_ip_white?(request.ip)
|
||||
@depp_user.errors.add(:base, I18n.t(:ip_is_not_whitelisted))
|
||||
end
|
||||
end
|
||||
|
||||
if @depp_user.errors.none? && @depp_user.valid?
|
||||
if @api_user.active?
|
||||
sign_in @api_user
|
||||
|
|
|
@ -9,6 +9,8 @@ class RegistrarController < ApplicationController
|
|||
false
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/PerceivedComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def check_ip
|
||||
return unless current_user
|
||||
unless current_user.is_a? ApiUser
|
||||
|
@ -16,11 +18,20 @@ class RegistrarController < ApplicationController
|
|||
return
|
||||
end
|
||||
return if Rails.env.development?
|
||||
return if current_user.registrar.registrar_ip_white?(request.ip)
|
||||
riw = current_user.registrar.registrar_ip_white?(request.ip)
|
||||
|
||||
aiw = true
|
||||
if current_user.can_make_api_calls?
|
||||
aiw = current_user.registrar.api_ip_white?(request.ip)
|
||||
end
|
||||
|
||||
return if riw && aiw
|
||||
flash[:alert] = t('access_denied')
|
||||
sign_out(current_user)
|
||||
redirect_to registrar_login_path and return
|
||||
end
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
|
||||
helper_method :head_title_sufix
|
||||
def head_title_sufix
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue