+ if (remote_user()) {
+ $host = substr(System::baseUrl() . ($a->path ? '/' . $a->path : ''), strpos(System::baseUrl(), '://') + 3);
+ $remotehost = substr($contact['addr'], strpos($contact['addr'], '@') + 1);
+
+ // On a local instance we have to check if the local user has already authenticated
+ // with the local contact. Otherwise the local user would ask the local contact
+ // for authentification everytime he/she is visiting a profile page of the local
+ // contact.
+ if ($host == $remotehost
+ && x($_SESSION, 'remote')
+ && is_array($_SESSION['remote']))
+ {
+ foreach ($_SESSION['remote'] as $v) {
+ if ($v['uid'] == $_SESSION['visitor_visiting'] && $v['cid'] == $_SESSION['visitor_id']) {
+ // Remote user is already authenticated.
+ $target_url = $url != '' ? $url : $contact_url;
+ logger($contact['name'] . " is already authenticated. Redirecting to " . $target_url, LOGGER_DEBUG);
+ goaway($target_url);
+ }
+ }
+ }
+ }