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 def create
authorize! :create, Depp::Domain authorize! :create, Depp::Domain
@domain_params = domain_params.to_h @domain_params = domain_params.to_h
if contacts_check = check_contacts
@data = @domain.create(@domain_params) @data = @domain.create(@domain_params)
end
if response_ok? if @data && response_ok?
redirect_to info_registrar_domains_url(domain_name: @domain_params[:name]) redirect_to info_registrar_domains_url(domain_name: @domain_params[:name])
else else
flash[:alert] = t('.email_error_message') unless contacts_check
render 'new' render 'new'
end end
end end
@ -110,12 +113,15 @@ class Registrar
def update def update
authorize! :update, Depp::Domain authorize! :update, Depp::Domain
@domain_params = params[:domain] @domain_params = params[:domain]
if contacts_check = check_contacts
@data = @domain.update(@domain_params) @data = @domain.update(@domain_params)
@dispute = Dispute.active.find_by(domain_name: @domain_params[:name]) @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]) redirect_to info_registrar_domains_url(domain_name: @domain_params[:name])
else else
flash[:alert] = t('.email_error_message') unless contacts_check
params[:domain_name] = @domain_params[:name] params[:domain_name] = @domain_params[:name]
render 'new' render 'new'
end end
@ -173,6 +179,11 @@ class Registrar
private 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 def init_domain
@domain = Depp::Domain.new(current_user: depp_current_user) @domain = Depp::Domain.new(current_user: depp_current_user)
end end

View file

@ -1,6 +1,8 @@
en: en:
registrar: registrar:
domains: domains:
email_error_message: 'Check contacts emails'
index: index:
header: Domains header: Domains
new_btn: New domain new_btn: New domain