Fix errors in Security namespace

pull/14590/head
Art4 2024-12-07 15:10:13 +00:00
parent d4e4c1505b
commit 780bfe0cbe
2 changed files with 13 additions and 31 deletions

View File

@ -15,6 +15,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\OpenWebAuthToken;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Network;
use Friendica\Util\Strings;

View File

@ -11,6 +11,9 @@ use Friendica\Security\TwoFactor;
use Friendica\Database\Database;
use Friendica\Security\TwoFactor\Exception\TrustedBrowserNotFoundException;
use Friendica\Security\TwoFactor\Exception\TrustedBrowserPersistenceException;
use Friendica\Security\TwoFactor\Collection\TrustedBrowsers as TrustedBrowsersCollection;
use Friendica\Security\TwoFactor\Factory\TrustedBrowser as TrustedBrowserFactory;
use Friendica\Security\TwoFactor\Model\TrustedBrowser as TrustedBrowserModel;
use Psr\Log\LoggerInterface;
class TrustedBrowser
@ -21,27 +24,27 @@ class TrustedBrowser
/** @var LoggerInterface */
protected $logger;
/** @var TwoFactor\Factory\TrustedBrowser */
/** @var TrustedBrowserFactory */
protected $factory;
protected static $table_name = '2fa_trusted_browser';
public function __construct(Database $database, LoggerInterface $logger, TwoFactor\Factory\TrustedBrowser $factory = null)
public function __construct(Database $database, LoggerInterface $logger, TrustedBrowserFactory $factory = null)
{
$this->db = $database;
$this->logger = $logger;
$this->factory = $factory ?? new TwoFactor\Factory\TrustedBrowser($logger);
$this->factory = $factory ?? new TrustedBrowserFactory($logger);
}
/**
* @param string $cookie_hash
*
* @return TwoFactor\Model\TrustedBrowser|null
* @return TrustedBrowserModel
*
* @throws TrustedBrowserPersistenceException
* @throws TrustedBrowserNotFoundException
*/
public function selectOneByHash(string $cookie_hash): TwoFactor\Model\TrustedBrowser
public function selectOneByHash(string $cookie_hash): TrustedBrowserModel
{
try {
$fields = $this->db->selectFirst(self::$table_name, [], ['cookie_hash' => $cookie_hash]);
@ -56,13 +59,9 @@ class TrustedBrowser
}
/**
* @param int $uid
*
* @return TwoFactor\Collection\TrustedBrowsers
*
* @throws TrustedBrowserPersistenceException
*/
public function selectAllByUid(int $uid): TwoFactor\Collection\TrustedBrowsers
public function selectAllByUid(int $uid): TrustedBrowsersCollection
{
try {
$rows = $this->db->selectToArray(self::$table_name, [], ['uid' => $uid]);
@ -71,7 +70,7 @@ class TrustedBrowser
foreach ($rows as $fields) {
$trustedBrowsers[] = $this->factory->createFromTableRow($fields);
}
return new TwoFactor\Collection\TrustedBrowsers($trustedBrowsers);
return new TrustedBrowsersCollection($trustedBrowsers);
} catch (\Exception $exception) {
throw new TrustedBrowserPersistenceException(sprintf('selection for uid \'%s\' wasn\'t successful.', $uid));
@ -79,13 +78,9 @@ class TrustedBrowser
}
/**
* @param TwoFactor\Model\TrustedBrowser $trustedBrowser
*
* @return bool
*
* @throws TrustedBrowserPersistenceException
*/
public function save(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool
public function save(TrustedBrowserModel $trustedBrowser): bool
{
try {
return $this->db->insert(self::$table_name, $trustedBrowser->toArray(), $this->db::INSERT_UPDATE);
@ -95,13 +90,9 @@ class TrustedBrowser
}
/**
* @param TwoFactor\Model\TrustedBrowser $trustedBrowser
*
* @return bool
*
* @throws TrustedBrowserPersistenceException
*/
public function remove(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool
public function remove(TrustedBrowserModel $trustedBrowser): bool
{
try {
return $this->db->delete(self::$table_name, ['cookie_hash' => $trustedBrowser->cookie_hash]);
@ -111,11 +102,6 @@ class TrustedBrowser
}
/**
* @param int $local_user
* @param string $cookie_hash
*
* @return bool
*
* @throws TrustedBrowserPersistenceException
*/
public function removeForUser(int $local_user, string $cookie_hash): bool
@ -127,11 +113,6 @@ class TrustedBrowser
}
}
/**
* @param int $local_user
*
* @return bool
*/
public function removeAllForUser(int $local_user): bool
{
try {