diff options
Diffstat (limited to 'app/models/email.rb')
-rw-r--r-- | app/models/email.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/app/models/email.rb b/app/models/email.rb index 580633d3232..c5154267ff0 100644 --- a/app/models/email.rb +++ b/app/models/email.rb @@ -6,7 +6,8 @@ class Email < ApplicationRecord belongs_to :user, optional: false - validates :email, presence: true, uniqueness: true, devise_email: true + validates :email, presence: true, uniqueness: true + validate :validate_email_format validate :unique_email, if: ->(email) { email.email_changed? } scope :confirmed, -> { where.not(confirmed_at: nil) } @@ -14,9 +15,14 @@ class Email < ApplicationRecord after_commit :update_invalid_gpg_signatures, if: -> { previous_changes.key?('confirmed_at') } devise :confirmable + + # This module adds async behaviour to Devise emails + # and should be added after Devise modules are initialized. + include AsyncDeviseEmail + self.reconfirmable = false # currently email can't be changed, no need to reconfirm - delegate :username, to: :user + delegate :username, :can?, to: :user def email=(value) write_attribute(:email, value.downcase.strip) @@ -30,6 +36,10 @@ class Email < ApplicationRecord user.accept_pending_invitations! end + def validate_email_format + self.errors.add(:email, I18n.t(:invalid, scope: 'valid_email.validations.email')) unless ValidateEmail.valid?(self.email) + end + # once email is confirmed, update the gpg signatures def update_invalid_gpg_signatures user.update_invalid_gpg_signatures if confirmed? |