From 6847909d9d25110aeedd2f08f0af96c2cd93bc99 Mon Sep 17 00:00:00 2001 From: barbara oliveira Date: Fri, 30 Aug 2024 13:56:43 +0200 Subject: [PATCH] add validation with registration_form --- .../friendly_signup/registration_form_override.rb | 15 +++++++++++++++ app/validators/email_validators.rb | 13 ------------- 2 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 app/forms/concerns/decidim/friendly_signup/registration_form_override.rb delete mode 100644 app/validators/email_validators.rb diff --git a/app/forms/concerns/decidim/friendly_signup/registration_form_override.rb b/app/forms/concerns/decidim/friendly_signup/registration_form_override.rb new file mode 100644 index 0000000..d1bb888 --- /dev/null +++ b/app/forms/concerns/decidim/friendly_signup/registration_form_override.rb @@ -0,0 +1,15 @@ +module Decidim + module FriendlySignup + class RegistrationFormOverride < Decidim::RegistrationForm + validate :no_special_characters_in_email + + private + + def no_special_characters_in_email + if email =~ /[<>'"]/ + errors.add(:email, "contains invalid characters") + end + end + end + end +end diff --git a/app/validators/email_validators.rb b/app/validators/email_validators.rb deleted file mode 100644 index 872c36e..0000000 --- a/app/validators/email_validators.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Decidim - module FriendlySignup - class EmailValidator < ActiveModel::EachValidator - CUSTOM_EMAIL_REGEX = /\A[^<>"']+@[a-zA-Z0-9\-.]+\.[a-zA-Z]{2,}/ - - def validate_each(record, attribute, value) - unless value =~ CUSTOM_EMAIL_REGEX - record.errors.add(attribute, :invalid_format, message: I18n.t("errors.messages.email.invalid_format")) - end - end - end - end -end