Commit b3635ee4 authored by Rémy Coutable's avatar Rémy Coutable

Re-add EmailValidator to avoid the repetition of format: { with: Devise.email_regexp }

parent b34963bc
...@@ -71,7 +71,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -71,7 +71,7 @@ class ApplicationSetting < ActiveRecord::Base
url: true url: true
validates :admin_notification_email, validates :admin_notification_email,
format: { with: Devise.email_regexp }, email: true,
allow_blank: true allow_blank: true
validates :two_factor_grace_period, validates :two_factor_grace_period,
......
...@@ -15,7 +15,7 @@ class Email < ActiveRecord::Base ...@@ -15,7 +15,7 @@ class Email < ActiveRecord::Base
belongs_to :user belongs_to :user
validates :user_id, presence: true validates :user_id, presence: true
validates :email, presence: true, uniqueness: true, format: { with: Devise.email_regexp } validates :email, presence: true, uniqueness: true, email: true
validate :unique_email, if: ->(email) { email.email_changed? } validate :unique_email, if: ->(email) { email.email_changed? }
before_validation :cleanup_email before_validation :cleanup_email
......
...@@ -38,8 +38,7 @@ class Member < ActiveRecord::Base ...@@ -38,8 +38,7 @@ class Member < ActiveRecord::Base
presence: { presence: {
if: :invite? if: :invite?
}, },
format: { email: {
with: Devise.email_regexp,
allow_nil: true allow_nil: true
}, },
uniqueness: { uniqueness: {
......
...@@ -146,8 +146,8 @@ class User < ActiveRecord::Base ...@@ -146,8 +146,8 @@ class User < ActiveRecord::Base
# Validations # Validations
# #
validates :name, presence: true validates :name, presence: true
validates :notification_email, presence: true, format: { with: Devise.email_regexp } validates :notification_email, presence: true, email: true
validates :public_email, presence: true, uniqueness: true, format: { with: Devise.email_regexp }, allow_blank: true validates :public_email, presence: true, uniqueness: true, email: true, allow_blank: true
validates :bio, length: { maximum: 255 }, allow_blank: true validates :bio, length: { maximum: 255 }, allow_blank: true
validates :projects_limit, presence: true, numericality: { greater_than_or_equal_to: 0 } validates :projects_limit, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :username, validates :username,
......
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid) unless value =~ Devise.email_regexp
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment