Skip to content

Commit

Permalink
Merge pull request #4022 from cesartalves/create-email-regexp-configu…
Browse files Browse the repository at this point in the history
…ration

Add global Spree::Config.default_email_regexp
  • Loading branch information
waiting-for-dev authored Jun 27, 2022
2 parents e47fdde + 5e451b5 commit d65a081
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class AppConfiguration < Preferences::Configuration
# @return [String] Two-letter ISO code of a {Spree::Country} to assumed as the country of an unidentified customer (default: "US")
preference :default_country_iso, :string, default: 'US'

# @!attribute [rw] default_email_regexp
# @return [Regexp] Regex to be used in email validations, for example in Spree::EmailValidator
preference :default_email_regexp, :regexp, default: URI::MailTo::EMAIL_REGEXP

# @!attribute [rw] generate_api_key_for_all_roles
# @return [Boolean] Allow generating api key automatically for user
# at role_user creation for all roles. (default: +false+)
Expand Down
4 changes: 3 additions & 1 deletion core/lib/spree/core/validators/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ module Spree
#
class EmailValidator < ActiveModel::EachValidator
EMAIL_REGEXP = URI::MailTo::EMAIL_REGEXP
# Use Spree::Config.default_email_regexp instead
deprecate_constant :EMAIL_REGEXP

def validate_each(record, attribute, value)
unless EMAIL_REGEXP.match? value
unless Spree::Config.default_email_regexp.match? value
record.errors.add(attribute, :invalid, **{ value: value }.merge!(options))
end
end
Expand Down

0 comments on commit d65a081

Please sign in to comment.