summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-28 22:24:14 -0700
committerStan Hu <stanhu@gmail.com>2018-07-28 22:24:14 -0700
commita5722c378bc88984657372267c16bb57168c02af (patch)
tree5091536bac4f9ee1f9ca2e89fa4df107db7016ac /app
parent6408cd00208c66f8657d68d904bc71d58f1d5000 (diff)
parent45ff4e31094a8b79ed603ae506990b6fa0e7c96e (diff)
downloadgitlab-ce-a5722c378bc88984657372267c16bb57168c02af.tar.gz
Merge commit '45ff4e31094a8b79ed603ae506990b6fa0e7c96e' into sh-support-bitbucket-server-import
Diffstat (limited to 'app')
-rw-r--r--app/models/user.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 58429f8d607..03549872924 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -248,6 +248,7 @@ class User < ActiveRecord::Base
scope :todo_authors, ->(user_id, state) { where(id: Todo.where(user_id: user_id, state: state).select(:author_id)) }
scope :order_recent_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'DESC')) }
scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'ASC')) }
+ scope :confirmed, -> { where.not(confirmed_at: nil) }
def self.with_two_factor_indistinct
joins("LEFT OUTER JOIN u2f_registrations AS u2f ON u2f.user_id = users.id")
@@ -293,14 +294,17 @@ class User < ActiveRecord::Base
end
# Find a User by their primary email or any associated secondary email
- def find_by_any_email(email)
- by_any_email(email).take
+ def find_by_any_email(email, confirmed: false)
+ by_any_email(email, confirmed: confirmed).take
end
# Returns a relation containing all the users for the given Email address
- def by_any_email(email)
+ def by_any_email(email, confirmed: false)
users = where(email: email)
+ users = users.confirmed if confirmed
+
emails = joins(:emails).where(emails: { email: email })
+ emails = emails.confirmed if confirmed
union = Gitlab::SQL::Union.new([users, emails])
from("(#{union.to_sql}) #{table_name}")