Parse contact information on domain creation

This commit is contained in:
Martin Lensment 2014-07-30 17:09:41 +03:00
parent 8882c36053
commit 338f85224a
3 changed files with 23 additions and 1 deletions

View file

@ -1,6 +1,7 @@
module Epp::DomainsHelper module Epp::DomainsHelper
def create_domain def create_domain
@domain = Domain.new(domain_create_params) @domain = Domain.new(domain_create_params)
@domain.create_contacts(domain_contacts)
if @domain.save if @domain.save
render '/epp/domains/create' render '/epp/domains/create'
@ -20,7 +21,6 @@ module Epp::DomainsHelper
def domain_create_params def domain_create_params
ph = params_hash['epp']['command']['create']['create'] ph = params_hash['epp']['command']['create']['create']
{ {
name: ph[:name], name: ph[:name],
registrar_id: current_epp_user.registrar.try(:id), registrar_id: current_epp_user.registrar.try(:id),
@ -32,6 +32,21 @@ module Epp::DomainsHelper
} }
end end
def domain_contacts
parsed_frame = Nokogiri::XML(params[:frame]).remove_namespaces!
res = {tech: [], admin: []}
parsed_frame.css('contact[type="tech"]').each do |x|
res[:tech] << Hash.from_xml(x.to_s)
end
parsed_frame.css('contact[type="admin"]').each do |x|
res[:admin] << Hash.from_xml(x.to_s)
end
res
end
def handle_domain_name_errors def handle_domain_name_errors
[:epp_domain_taken, :epp_domain_reserved].each do |x| [:epp_domain_taken, :epp_domain_reserved].each do |x|
if @domain.errors.added?(:name, x) if @domain.errors.added?(:name, x)

View file

@ -21,6 +21,12 @@ class Domain < ActiveRecord::Base
write_attribute(:name_dirty, value) write_attribute(:name_dirty, value)
end end
def create_contacts(contacts)
contacts[:tech].each do |x|
end
end
class << self class << self
def check_availability(domains) def check_availability(domains)
domains = [domains] if domains.is_a?(String) domains = [domains] if domains.is_a?(String)

View file

@ -13,6 +13,7 @@
<domain:registrant>jd1234</domain:registrant> <domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact> <domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact> <domain:contact type="tech">sh8013</domain:contact>
<domain:contact type="tech">sh801333</domain:contact>
<domain:authInfo> <domain:authInfo>
<domain:pw>2fooBAR</domain:pw> <domain:pw>2fooBAR</domain:pw>
</domain:authInfo> </domain:authInfo>