diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-04 21:06:04 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-04 21:06:04 +0200 |
commit | 54ea7f5dfeb2ecbad6362b050e234da366906666 (patch) | |
tree | 5568a6faf666092abeff04b83dcba53c448f591d /app/models | |
parent | a82f2e4b824ee09419871d6cbb5284368dd83f24 (diff) |
Case-insensitive search by usernames
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/account.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index af8b6cc3d..bcd6c1eba 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -96,8 +96,12 @@ class Account < ApplicationRecord end def self.find_local!(username) + self.find_remote!(username, nil) + end + + def self.find_remote!(username, domain) table = self.arel_table - self.where(table[:username].matches(username)).where(domain: nil).take! + self.where(table[:username].matches(username)).where(domain: domain).take! end def self.find_local(username) @@ -106,6 +110,12 @@ class Account < ApplicationRecord nil end + def self.find_remote(username, domain) + self.find_remote!(username, domain) + rescue ActiveRecord::RecordNotFound + nil + end + before_create do if local? keypair = OpenSSL::PKey::RSA.new(Rails.env.test? ? 1024 : 2048) |