X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FMagic.php;h=1012dc72baffdbb57fddcb6e69b2ae50e32b7e19;hb=423e60174ef7ae4948fa44ac725c8bc54234966a;hp=63f8ee9c1c54029428b4a24cea33520306c6c4c5;hpb=714f0febc4918f5569eb09f8800b6739cff36347;p=friendica.git diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 63f8ee9c1c..1012dc72ba 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -1,6 +1,6 @@ false, 'url' => '', 'message' => '']; - Logger::info('magic mdule: invoked'); + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); - Logger::debug('args', ['request' => $_REQUEST]); + $this->app = $app; + $this->dba = $dba; + $this->httpClient = $httpClient; + $this->userSession = $userSession; + } + + protected function rawContent(array $request = []) + { + $this->logger->info('magic module: invoked'); + + $this->logger->debug('args', ['request' => $_REQUEST]); $addr = $_REQUEST['addr'] ?? ''; $dest = $_REQUEST['dest'] ?? ''; - $test = (!empty($_REQUEST['test']) ? intval($_REQUEST['test']) : 0); $owa = (!empty($_REQUEST['owa']) ? intval($_REQUEST['owa']) : 0); $cid = 0; @@ -60,27 +81,21 @@ class Magic extends BaseModule } if (!$cid) { - Logger::info('No contact record found', $_REQUEST); + $this->logger->info('No contact record found', $_REQUEST); // @TODO Finding a more elegant possibility to redirect to either internal or external URL - $a->redirect($dest); + $this->app->redirect($dest); } - $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); + $contact = $this->dba->selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); // Redirect if the contact is already authenticated on this site. - if ($a->getContactId() && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) { - if ($test) { - $ret['success'] = true; - $ret['message'] .= 'Local site - you are already authenticated.' . EOL; - return $ret; - } - - Logger::info('Contact is already authenticated'); + if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl)) !== false) { + $this->logger->info('Contact is already authenticated'); System::externalRedirect($dest); } // OpenWebAuth - if (local_user() && $owa) { - $user = User::getById(local_user()); + if ($this->userSession->getLocalUserId() && $owa) { + $user = User::getById($this->userSession->getLocalUserId()); // Extract the basepath // NOTE: we need another solution because this does only work @@ -98,11 +113,11 @@ class Magic extends BaseModule $header = HTTPSignature::createSig( $header, $user['prvkey'], - 'acct:' . $user['nickname'] . '@' . DI::baseUrl()->getHostname() . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '') + 'acct:' . $user['nickname'] . '@' . $this->baseUrl->getHost() . ($this->baseUrl->getPath() ? '/' . $this->baseUrl->getPath() : '') ); // Try to get an authentication token from the other instance. - $curlResult = DI::httpClient()->get($basepath . '/owa', [HttpClientOptions::HEADERS => $header]); + $curlResult = $this->httpClient->get($basepath . '/owa', HttpClientAccept::DEFAULT, [HttpClientOptions::HEADERS => $header]); if ($curlResult->isSuccess()) { $j = json_decode($curlResult->getBody(), true); @@ -118,19 +133,14 @@ class Magic extends BaseModule } $args = (strpbrk($dest, '?&') ? '&' : '?') . 'owt=' . $token; - Logger::info('Redirecting', ['path' => $dest . $args]); + $this->logger->info('Redirecting', ['path' => $dest . $args]); System::externalRedirect($dest . $args); } } System::externalRedirect($dest); } - if ($test) { - $ret['message'] = 'Not authenticated or invalid arguments' . EOL; - return $ret; - } - // @TODO Finding a more elegant possibility to redirect to either internal or external URL - $a->redirect($dest); + $this->app->redirect($dest); } }