diff options
author | Brett Walker <brett@digitalmoksha.com> | 2017-09-20 14:24:10 +0300 |
---|---|---|
committer | Brett Walker <brett@digitalmoksha.com> | 2017-09-23 16:26:04 +0300 |
commit | 665c7876faadc41e1c7a77bb423b951cbcb020ce (patch) | |
tree | 6250727aee6c97f50e4f254da3c1bc0717206fee /app | |
parent | ed99c899a28134e8d9a1a8a8c4677a6ee65bbd2b (diff) |
added email.confirmed scope and fix email comparison
Diffstat (limited to 'app')
-rw-r--r-- | app/models/email.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 5 |
2 files changed, 6 insertions, 3 deletions
diff --git a/app/models/email.rb b/app/models/email.rb index 085663a4fef..041fbbfbe44 100644 --- a/app/models/email.rb +++ b/app/models/email.rb @@ -7,6 +7,8 @@ class Email < ActiveRecord::Base validates :email, presence: true, uniqueness: true, email: true validate :unique_email, if: ->(email) { email.email_changed? } + scope :confirmed, -> { where.not(confirmed_at: nil) } + after_commit :update_invalid_gpg_signatures, if: -> { previous_changes.key?('confirmed_at') } devise :confirmable @@ -19,7 +21,7 @@ class Email < ActiveRecord::Base def unique_email self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email) end - + # once email is confirmed, update the gpg signatures def update_invalid_gpg_signatures user.update_invalid_gpg_signatures if confirmed? diff --git a/app/models/user.rb b/app/models/user.rb index c75107472d6..3be3b205ea8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -837,12 +837,13 @@ class User < ActiveRecord::Base def verified_emails verified_emails = [] verified_emails << email if primary_email_verified? - verified_emails.concat(emails.where.not(confirmed_at: nil).pluck(:email)) + verified_emails.concat(emails.confirmed.pluck(:email)) verified_emails end def verified_email?(check_email) - (email == check_email && primary_email_verified?) || verified_emails.include?(check_email) + downcased = check_email.downcase + (email == downcased && primary_email_verified?) || emails.confirmed.where(email: downcased).exists? end def hook_attrs |