Add email checking for creating/updating domains

This commit is contained in:
dinsmol 2021-12-14 09:27:13 +03:00 committed by olegphenomenon
parent 102fd559a0
commit 6b028814c3
2 changed files with 18 additions and 5 deletions

View file

@ -91,11 +91,14 @@ class Registrar
def create
authorize! :create, Depp::Domain
@domain_params = domain_params.to_h
@data = @domain.create(@domain_params)
if contacts_check = check_contacts
@data = @domain.create(@domain_params)
end
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 contacts_check
render 'new'
end
end
@ -110,12 +113,15 @@ class Registrar
def update
authorize! :update, Depp::Domain
@domain_params = params[:domain]
@data = @domain.update(@domain_params)
@dispute = Dispute.active.find_by(domain_name: @domain_params[:name])
if contacts_check = check_contacts
@data = @domain.update(@domain_params)
@dispute = Dispute.active.find_by(domain_name: @domain_params[:name])
end
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 contacts_check
params[:domain_name] = @domain_params[:name]
render 'new'
end
@ -173,6 +179,11 @@ class Registrar
private
def check_contacts
params_as_hash = @domain_params[:contacts_attributes].to_h
params_as_hash.all? { |_k, val| Contact.find_by(code: val[:code]).verify_email }
end
def init_domain
@domain = Depp::Domain.new(current_user: depp_current_user)
end