mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 14:06:21 +02:00
Merge pull request #2240 from internetee/2213-email-checking
Email checking for creating/updating domains
This commit is contained in:
commit
b15ef00d77
4 changed files with 49 additions and 3 deletions
|
@ -88,14 +88,16 @@ class Registrar
|
|||
@domain_params[:period] = Depp::Domain.default_period
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CognitiveComplexity
|
||||
def create
|
||||
authorize! :create, Depp::Domain
|
||||
@domain_params = domain_params.to_h
|
||||
@data = @domain.create(@domain_params)
|
||||
|
||||
if response_ok?
|
||||
if @data && response_ok?
|
||||
redirect_to info_registrar_domains_url(domain_name: @domain_params[:name])
|
||||
else
|
||||
flash[:alert] = t('.email_error_message') unless @emails_check_result
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
@ -113,13 +115,15 @@ class Registrar
|
|||
@data = @domain.update(@domain_params)
|
||||
@dispute = Dispute.active.find_by(domain_name: @domain_params[:name])
|
||||
|
||||
if response_ok?
|
||||
if @data && response_ok?
|
||||
redirect_to info_registrar_domains_url(domain_name: @domain_params[:name])
|
||||
else
|
||||
flash[:alert] = t('.email_error_message') unless @emails_check_result
|
||||
params[:domain_name] = @domain_params[:name]
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/CognitiveComplexity
|
||||
|
||||
def delete
|
||||
authorize! :delete, Depp::Domain
|
||||
|
|
|
@ -45,6 +45,10 @@ module Actions
|
|||
def assign_new_registrant
|
||||
domain.add_epp_error('2306', nil, nil, %i[registrant cannot_be_missing]) unless params[:registrant][:code]
|
||||
|
||||
contact_code = params[:registrant][:code]
|
||||
contact = Contact.find_by(code: contact_code)
|
||||
validate_email(contact.email)
|
||||
|
||||
regt = Registrant.find_by(code: params[:registrant][:code])
|
||||
unless regt
|
||||
domain.add_epp_error('2303', 'registrant', params[:registrant], %i[registrant not_found])
|
||||
|
@ -120,9 +124,35 @@ module Actions
|
|||
@dnskeys << { id: dnkey.id, _destroy: 1 } if dnkey
|
||||
end
|
||||
|
||||
def start_validate_email(props)
|
||||
contact_code = props[0][:contact_code_cache]
|
||||
contact = Contact.find_by(code: contact_code)
|
||||
|
||||
return if contact.nil?
|
||||
|
||||
validate_email(contact.email)
|
||||
end
|
||||
|
||||
def validate_email(email)
|
||||
return true if Rails.env.test?
|
||||
|
||||
[:regex, :mx].each do |m|
|
||||
result = Actions::SimpleMailValidator.run(email: email, level: m)
|
||||
next if result
|
||||
|
||||
domain.add_epp_error('2005', nil, "#{email} didn't pass validation", I18n.t(:parameter_value_syntax_error))
|
||||
@error = true
|
||||
return
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def assign_admin_contact_changes
|
||||
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'admin' })
|
||||
|
||||
start_validate_email(props) if props.present?
|
||||
|
||||
if props.any? && domain.admin_change_prohibited?
|
||||
domain.add_epp_error('2304', 'admin', DomainStatus::SERVER_ADMIN_CHANGE_PROHIBITED,
|
||||
I18n.t(:object_status_prohibits_operation))
|
||||
|
@ -136,6 +166,8 @@ module Actions
|
|||
props = gather_domain_contacts(params[:contacts].select { |c| c[:type] == 'tech' },
|
||||
admin: false)
|
||||
|
||||
start_validate_email(props) if props.present?
|
||||
|
||||
if props.any? && domain.tech_change_prohibited?
|
||||
domain.add_epp_error('2304', 'tech', DomainStatus::SERVER_TECH_CHANGE_PROHIBITED,
|
||||
I18n.t(:object_status_prohibits_operation))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue