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
/** @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]);
}
/**
- * @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]);
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));
}
/**
- * @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);
}
/**
- * @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]);
}
/**
- * @param int $local_user
- * @param string $cookie_hash
- *
- * @return bool
- *
* @throws TrustedBrowserPersistenceException
*/
public function removeForUser(int $local_user, string $cookie_hash): bool
}
}
- /**
- * @param int $local_user
- *
- * @return bool
- */
public function removeAllForUser(int $local_user): bool
{
try {