mirror of
https://github.com/friendica/friendica
synced 2024-12-22 18:40:17 +00:00
Fix errors in Security namespace
This commit is contained in:
parent
d4e4c1505b
commit
780bfe0cbe
2 changed files with 13 additions and 31 deletions
|
@ -15,6 +15,7 @@ use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\OpenWebAuthToken;
|
use Friendica\Model\OpenWebAuthToken;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Util\HTTPSignature;
|
use Friendica\Util\HTTPSignature;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
|
@ -11,6 +11,9 @@ use Friendica\Security\TwoFactor;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Security\TwoFactor\Exception\TrustedBrowserNotFoundException;
|
use Friendica\Security\TwoFactor\Exception\TrustedBrowserNotFoundException;
|
||||||
use Friendica\Security\TwoFactor\Exception\TrustedBrowserPersistenceException;
|
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;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class TrustedBrowser
|
class TrustedBrowser
|
||||||
|
@ -21,27 +24,27 @@ class TrustedBrowser
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
/** @var TwoFactor\Factory\TrustedBrowser */
|
/** @var TrustedBrowserFactory */
|
||||||
protected $factory;
|
protected $factory;
|
||||||
|
|
||||||
protected static $table_name = '2fa_trusted_browser';
|
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->db = $database;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->factory = $factory ?? new TwoFactor\Factory\TrustedBrowser($logger);
|
$this->factory = $factory ?? new TrustedBrowserFactory($logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $cookie_hash
|
* @param string $cookie_hash
|
||||||
*
|
*
|
||||||
* @return TwoFactor\Model\TrustedBrowser|null
|
* @return TrustedBrowserModel
|
||||||
*
|
*
|
||||||
* @throws TrustedBrowserPersistenceException
|
* @throws TrustedBrowserPersistenceException
|
||||||
* @throws TrustedBrowserNotFoundException
|
* @throws TrustedBrowserNotFoundException
|
||||||
*/
|
*/
|
||||||
public function selectOneByHash(string $cookie_hash): TwoFactor\Model\TrustedBrowser
|
public function selectOneByHash(string $cookie_hash): TrustedBrowserModel
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$fields = $this->db->selectFirst(self::$table_name, [], ['cookie_hash' => $cookie_hash]);
|
$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
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function selectAllByUid(int $uid): TwoFactor\Collection\TrustedBrowsers
|
public function selectAllByUid(int $uid): TrustedBrowsersCollection
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$rows = $this->db->selectToArray(self::$table_name, [], ['uid' => $uid]);
|
$rows = $this->db->selectToArray(self::$table_name, [], ['uid' => $uid]);
|
||||||
|
@ -71,7 +70,7 @@ class TrustedBrowser
|
||||||
foreach ($rows as $fields) {
|
foreach ($rows as $fields) {
|
||||||
$trustedBrowsers[] = $this->factory->createFromTableRow($fields);
|
$trustedBrowsers[] = $this->factory->createFromTableRow($fields);
|
||||||
}
|
}
|
||||||
return new TwoFactor\Collection\TrustedBrowsers($trustedBrowsers);
|
return new TrustedBrowsersCollection($trustedBrowsers);
|
||||||
|
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new TrustedBrowserPersistenceException(sprintf('selection for uid \'%s\' wasn\'t successful.', $uid));
|
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
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function save(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool
|
public function save(TrustedBrowserModel $trustedBrowser): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->db->insert(self::$table_name, $trustedBrowser->toArray(), $this->db::INSERT_UPDATE);
|
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
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function remove(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool
|
public function remove(TrustedBrowserModel $trustedBrowser): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->db->delete(self::$table_name, ['cookie_hash' => $trustedBrowser->cookie_hash]);
|
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
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function removeForUser(int $local_user, string $cookie_hash): bool
|
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
|
public function removeAllForUser(int $local_user): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue