about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-03 16:57:44 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-03 16:57:44 +0100
commit3731230c6d25f248afa8a17b62b3db70fdfe1e03 (patch)
tree9e7da1198a5e20c600add1cad4c0c288c524d1f9 /app/services
parente4671adc25081161268c885b3427fd84cbecb249 (diff)
Allow @username@domain/@username in follow form, prevent duplicate accounts
created via remote look-up when domains differ but point to the same resource
Diffstat (limited to 'app/services')
-rw-r--r--app/services/follow_remote_account_service.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/services/follow_remote_account_service.rb b/app/services/follow_remote_account_service.rb
index 0a95badb2..b309425a8 100644
--- a/app/services/follow_remote_account_service.rb
+++ b/app/services/follow_remote_account_service.rb
@@ -15,16 +15,25 @@ class FollowRemoteAccountService < BaseService
     return nil if DomainBlock.blocked?(domain)
 
     account = Account.find_remote(username, domain)
-
     return account unless account.nil?
 
-    Rails.logger.debug "Creating new remote account for #{uri}"
+    Rails.logger.debug "Looking up webfinger for #{uri}"
+
     account = Account.new(username: username, domain: domain)
 
     data = Goldfinger.finger("acct:#{uri}")
 
     raise Goldfinger::Error, 'Missing resource links' if data.link('http://schemas.google.com/g/2010#updates-from').nil? || data.link('salmon').nil? || data.link('http://webfinger.net/rel/profile-page').nil? || data.link('magic-public-key').nil?
 
+    confirmed_username, confirmed_domain = data.subject.gsub(/\Aacct:/, '').split('@')
+
+    return Account.find_local(confirmed_username) if TagManager.instance.local_domain?(confirmed_domain)
+
+    confirmed_account = Account.find_remote(confirmed_username, confirmed_domain)
+    return confirmed_account unless confirmed_account.nil?
+
+    Rails.logger.debug "Creating new remote account for #{uri}"
+
     account.remote_url  = data.link('http://schemas.google.com/g/2010#updates-from').href
     account.salmon_url  = data.link('salmon').href
     account.url         = data.link('http://webfinger.net/rel/profile-page').href