- // When the remote page does support OWA, then we enforce the use of it
- $basepath = Contact::getBasepath($contact_url);
- if (Strings::compareLink($basepath, System::baseUrl())) {
- $use_magic = true;
- } else {
- $serverret = Network::curl($basepath . '/magic');
- $use_magic = $serverret->isSuccess();
+ if (remote_user()) {
+ $host = substr(DI::baseUrl()->getUrlPath() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : ''), strpos(DI::baseUrl()->getUrlPath(), '://') + 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) && (Session::getRemoteContactID(Session::get('visitor_visiting')) == Session::get('visitor_id'))) {
+ // Remote user is already authenticated.
+ redir_check_url($contact_url, $url);
+ $target_url = $url ?: $contact_url;
+ Logger::log($contact['name'] . " is already authenticated. Redirecting to " . $target_url, Logger::DEBUG);
+ $a->redirect($target_url);