Replace all calls for App::getContactId() with AppHelper

This commit is contained in:
Art4 2024-11-08 23:04:52 +00:00
parent cad3311afb
commit d9087b4f7c
4 changed files with 46 additions and 39 deletions

View file

@ -8,7 +8,9 @@
namespace Friendica\Module;
use Exception;
use Friendica\App;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\AppHelper;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
@ -35,8 +37,8 @@ use Psr\Log\LoggerInterface;
*/
class Magic extends BaseModule
{
/** @var App */
protected $app;
/** @var AppHelper */
protected $appHelper;
/** @var Database */
protected $dba;
/** @var ICanSendHttpRequests */
@ -44,11 +46,11 @@ class Magic extends BaseModule
/** @var IHandleUserSessions */
protected $userSession;
public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, IHandleUserSessions $userSession, $server, array $parameters = [])
public function __construct(AppHelper $appHelper, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, Database $dba, ICanSendHttpRequests $httpClient, IHandleUserSessions $userSession, $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->app = $app;
$this->appHelper = $appHelper;
$this->dba = $dba;
$this->httpClient = $httpClient;
$this->userSession = $userSession;
@ -85,11 +87,11 @@ class Magic extends BaseModule
if (empty($contact)) {
if (!$owa) {
$this->logger->info('No contact record found, no oWA, redirecting to destination.', ['request' => $request, 'server' => $_SERVER, 'dest' => $dest]);
$this->app->redirect($dest);
$this->appHelper->redirect($dest);
}
} else {
// Redirect if the contact is already authenticated on this site.
if ($this->app->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl)) !== false) {
if ($this->appHelper->getContactId() && strpos($contact['nurl'], Strings::normaliseLink($this->baseUrl)) !== false) {
$this->logger->info('Contact is already authenticated, redirecting to destination.', ['dest' => $dest]);
System::externalRedirect($dest);
}
@ -99,12 +101,12 @@ class Magic extends BaseModule
if (!$this->userSession->getLocalUserId() || !$owa) {
$this->logger->notice('Not logged in or not OWA, redirecting to destination.', ['uid' => $this->userSession->getLocalUserId(), 'owa' => $owa, 'dest' => $dest]);
$this->app->redirect($dest);
$this->appHelper->redirect($dest);
}
$dest = Network::removeUrlParameter($dest, 'zid');
$dest = Network::removeUrlParameter($dest, 'f');
// OpenWebAuth
$owner = User::getOwnerDataById($this->userSession->getLocalUserId());
@ -169,7 +171,7 @@ class Magic extends BaseModule
$j = json_decode($curlResult->getBodyString(), true);
if (empty($j) || !$j['success']) {
$this->logger->notice('Invalid JSON, redirecting to destination.', ['json' => $j, 'dest' => $dest]);
$this->app->redirect($dest);
$this->appHelper->redirect($dest);
}
if ($j['encrypted_token']) {