From 54ea7f5dfeb2ecbad6362b050e234da366906666 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 4 Sep 2016 21:06:04 +0200 Subject: Case-insensitive search by usernames --- app/models/account.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'app/models') 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) -- cgit