From 41feb7c601986ea2c12a971949e8455b92b0e239 Mon Sep 17 00:00:00 2001 From: olegphenomenon Date: Tue, 2 Nov 2021 14:21:05 +0200 Subject: [PATCH] added trumail validator after update and implement simple email validator interaction --- app/interactions/actions/contact_update.rb | 18 ++++++++++++++++++ .../actions/simple_mail_validator.rb | 9 +++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/interactions/actions/simple_mail_validator.rb diff --git a/app/interactions/actions/contact_update.rb b/app/interactions/actions/contact_update.rb index f66aae805..b34069a89 100644 --- a/app/interactions/actions/contact_update.rb +++ b/app/interactions/actions/contact_update.rb @@ -15,9 +15,27 @@ module Actions maybe_update_statuses maybe_update_ident if ident.present? maybe_attach_legal_doc + maybe_change_email commit end + def maybe_change_email + return if Rails.env.test? + + [:regex, :mx].each do |m| + # r = Truemail.validate(@new_attributes[:email], with: m) + r = Actions::SimpleMailValidator.run(email: @new_attributes[:email], level: m) + + unless r.success + contact.add_epp_error('2306', nil, r.errors, I18n.t(:client_side_status_editing_error)) + @error = true + return + end + end + + true + end + def maybe_remove_address return if Contact.address_processing? diff --git a/app/interactions/actions/simple_mail_validator.rb b/app/interactions/actions/simple_mail_validator.rb new file mode 100644 index 000000000..b96c3db46 --- /dev/null +++ b/app/interactions/actions/simple_mail_validator.rb @@ -0,0 +1,9 @@ +module Actions + module SimpleMailValidator + extend self + + def run(email:, level:) + Truemail.validate(email, with: level).result + end + end +end