Refactor EPP users to API users

This commit is contained in:
Martin Lensment 2015-01-29 14:13:49 +02:00
parent b8494993ea
commit c91c9c8ebf
44 changed files with 154 additions and 150 deletions

View file

@ -3,12 +3,12 @@ class Epp::ContactsController < EppController
helper WhodunnitHelper ## Refactor this?
def user_for_paper_trail ## Refactor this?
current_epp_user ? "#{current_epp_user.id}-EppUser" : nil
current_api_user ? "#{current_api_user.id}-ApiUser" : nil
end
def create
@contact = Contact.new(contact_and_address_attributes)
@contact.registrar = current_epp_user.registrar
@contact.registrar = current_api_user.registrar
render_epp_response '/epp/contacts/create' and return if stamp(@contact) && @contact.save
handle_errors(@contact)
end
@ -113,7 +113,7 @@ class Epp::ContactsController < EppController
return false unless xml_attrs_present?(@ph, [['id']])
@contact = find_contact
return false unless @contact
return true if current_epp_user.registrar == @contact.registrar || xml_attrs_present?(@ph, [%w(authInfo pw)])
return true if current_api_user.registrar == @contact.registrar || xml_attrs_present?(@ph, [%w(authInfo pw)])
false
end
@ -135,7 +135,7 @@ class Epp::ContactsController < EppController
def owner?(with_errors = true)
return false unless find_contact
return true if @contact.registrar == current_epp_user.registrar
return true if @contact.registrar == current_api_user.registrar
return false unless with_errors
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error') }
false
@ -144,7 +144,7 @@ class Epp::ContactsController < EppController
def rights?
pw = @ph.try(:[], :authInfo).try(:[], :pw)
return true if current_epp_user.try(:registrar) == @contact.try(:registrar)
return true if current_api_user.try(:registrar) == @contact.try(:registrar)
return true if pw && @contact.auth_info_matches(pw) # @contact.try(:auth_info_matches, pw)
epp_errors << { code: '2200', msg: t('errors.messages.epp_authentication_error') }

View file

@ -175,7 +175,7 @@ class Epp::DomainsController < EppController
{
name: name,
registrar_id: current_epp_user.registrar.try(:id),
registrar_id: current_api_user.registrar.try(:id),
registered_at: Time.now,
period: (period.to_i == 0) ? 1 : period.to_i,
period_unit: Epp::EppDomain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y'
@ -186,7 +186,7 @@ class Epp::DomainsController < EppController
res = {}
res[:pw] = params[:parsed_frame].css('pw').first.try(:text)
res[:action] = params[:parsed_frame].css('transfer').first[:op]
res[:current_user] = current_epp_user
res[:current_user] = current_api_user
res
end
@ -205,7 +205,7 @@ class Epp::DomainsController < EppController
return domain if domain.auth_info == params[:parsed_frame].css('authInfo pw').text
if (domain.registrar != current_epp_user.registrar && secure[:secure] == true) &&
if (domain.registrar != current_api_user.registrar && secure[:secure] == true) &&
epp_errors << {
code: '2302',
msg: I18n.t('errors.messages.domain_exists_but_belongs_to_other_registrar'),

View file

@ -6,7 +6,7 @@ class Epp::KeyrelaysController < EppController
handle_errors(@domain) and return unless @domain
handle_errors(@domain) and return unless @domain.authenticate(params[:parsed_frame].css('pw').text)
handle_errors(@domain) and return unless @domain.keyrelay(params[:parsed_frame], current_epp_user.registrar)
handle_errors(@domain) and return unless @domain.keyrelay(params[:parsed_frame], current_api_user.registrar)
render_epp_response '/epp/shared/success'
end

View file

@ -5,7 +5,7 @@ class Epp::PollsController < EppController
end
def req_poll
@message = current_epp_user.queued_messages.last
@message = current_api_user.queued_messages.last
render_epp_response 'epp/poll/poll_no_messages' and return unless @message
if @message.attached_obj_type && @message.attached_obj_id
@ -20,7 +20,7 @@ class Epp::PollsController < EppController
end
def ack_poll
@message = current_epp_user.queued_messages.find_by(id: params[:parsed_frame].css('poll').first['msgID'])
@message = current_api_user.queued_messages.find_by(id: params[:parsed_frame].css('poll').first['msgID'])
unless @message
epp_errors << {

View file

@ -4,10 +4,10 @@ class Epp::SessionsController < EppController
end
def login
@epp_user = EppUser.find_by(login_params)
@api_user = ApiUser.find_by(login_params)
if @epp_user.try(:active)
epp_session[:epp_user_id] = @epp_user.id
if @api_user.try(:active)
epp_session[:api_user_id] = @api_user.id
render_epp_response('login_success')
else
response.headers['X-EPP-Returncode'] = '2200'
@ -16,8 +16,8 @@ class Epp::SessionsController < EppController
end
def logout
@epp_user = current_epp_user # cache current_epp_user for logging
epp_session[:epp_user_id] = nil
@api_user = current_api_user # cache current_api_user for logging
epp_session[:api_user_id] = nil
response.headers['X-EPP-Returncode'] = '1500'
render_epp_response('logout')
end