Refactor epp routing

This commit is contained in:
Martin Lensment 2015-01-16 13:26:54 +02:00
parent fcc4477f68
commit db77334711
5 changed files with 95 additions and 8 deletions

View file

@ -8,8 +8,8 @@ module Epp::Common
included do
protect_from_forgery with: :null_session
before_action :validate_request, only: [:proxy]
before_action :validate_request
layout false
helper_method :current_epp_user
end
@ -108,7 +108,7 @@ module Epp::Common
# rubocop: enable Style/PredicateName
def validate_request
validation_method = "validate_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}_#{params[:command]}_request"
validation_method = "validate_#{params[:action]}"
return unless respond_to?(validation_method, true)
handle_errors and return unless send(validation_method)
end
@ -123,7 +123,7 @@ module Epp::Common
request_object = OBJECT_TYPES[params_hash['epp']['xmlns:ns2']] if params[:frame]
ApiLog::EppLog.create({
request: params[:raw_frame],
request_command: params[:command],
request_command: params[:action],
request_successful: epp_errors.empty?,
request_object: request_object,
response: @response,

View file

@ -0,0 +1,9 @@
class Epp::ContactsController < ApplicationController
protect_from_forgery with: :null_session
def create
end
def info
end
end

View file

@ -0,0 +1,51 @@
class Epp::DomainsController < ApplicationController
include Epp::Common
def create
end
def info
@domain = find_domain
handle_errors(@domain) and return unless @domain
render_epp_response '/epp/domains/info'
end
def check
names = params[:parsed_frame].css('name').map(&:text)
@domains = Epp::EppDomain.check_availability(names)
render_epp_response '/epp/domains/check'
end
private
def validate_check
epp_request_valid?('name')
end
def find_domain(secure = { secure: true })
domain_name = params[:parsed_frame].css('name').text.strip.downcase
domain = Epp::EppDomain.find_by(name: domain_name)
unless domain
epp_errors << {
code: '2303',
msg: I18n.t('errors.messages.epp_domain_not_found'),
value: { obj: 'name', val: domain_name }
}
return nil
end
return domain if domain.auth_info == params[:parsed_frame].css('authInfo pw').text
if (domain.registrar != current_epp_user.registrar && secure[:secure] == true) &&
epp_errors << {
code: '2302',
msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'),
value: { obj: 'name', val: params[:parsed_frame].css('name').text.strip.downcase }
}
return nil
end
domain
end
end