about summary refs log tree commit diff
path: root/app/validators
diff options
context:
space:
mode:
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/unique_username_validator.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/app/validators/unique_username_validator.rb b/app/validators/unique_username_validator.rb
index 4e24e3f5f..f87eb06ba 100644
--- a/app/validators/unique_username_validator.rb
+++ b/app/validators/unique_username_validator.rb
@@ -7,8 +7,9 @@ class UniqueUsernameValidator < ActiveModel::Validator
     return if account.username.nil?
 
     normalized_username = account.username.downcase
+    normalized_domain = account.domain&.downcase
 
-    scope = Account.where(domain: nil).where('lower(username) = ?', normalized_username)
+    scope = Account.where(Account.arel_table[:username].lower.eq normalized_username).where(Account.arel_table[:domain].lower.eq normalized_domain)
     scope = scope.where.not(id: account.id) if account.persisted?
 
     account.errors.add(:username, :taken) if scope.exists?