adhere use
and type-hints :-)
This commit is contained in:
parent
b31c2f4ec1
commit
e8fd495847
|
@ -33,6 +33,8 @@ use Friendica\Network\HTTPException\FoundException;
|
||||||
use Friendica\Network\HTTPException\MovedPermanentlyException;
|
use Friendica\Network\HTTPException\MovedPermanentlyException;
|
||||||
use Friendica\Network\HTTPException\TemporaryRedirectException;
|
use Friendica\Network\HTTPException\TemporaryRedirectException;
|
||||||
use Friendica\Security\Authentication;
|
use Friendica\Security\Authentication;
|
||||||
|
use Friendica\Security\TwoFactor\Exception\TrustedBrowserNotFoundException;
|
||||||
|
use Friendica\Security\TwoFactor\Exception\TrustedBrowserPersistenceException;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Friendica\Security\TwoFactor;
|
use Friendica\Security\TwoFactor;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -92,7 +94,7 @@ class Trust extends BaseModule
|
||||||
if (!$this->cookie->set('2fa_cookie_hash', $trustedBrowser->cookie_hash)) {
|
if (!$this->cookie->set('2fa_cookie_hash', $trustedBrowser->cookie_hash)) {
|
||||||
notice($this->t('Couldn\'t save browser to Cookie.'));
|
notice($this->t('Couldn\'t save browser to Cookie.'));
|
||||||
};
|
};
|
||||||
} catch (TwoFactor\Exception\TrustedBrowserPersistenceException $exception) {
|
} catch (TrustedBrowserPersistenceException $exception) {
|
||||||
$this->logger->warning('Unexpected error when saving the trusted browser.', ['trustedBrowser' => $trustedBrowser, 'exception' => $exception]);
|
$this->logger->warning('Unexpected error when saving the trusted browser.', ['trustedBrowser' => $trustedBrowser, 'exception' => $exception]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -122,9 +124,9 @@ class Trust extends BaseModule
|
||||||
$this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true);
|
$this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true);
|
||||||
$this->baseUrl->redirect();
|
$this->baseUrl->redirect();
|
||||||
}
|
}
|
||||||
} catch (TwoFactor\Exception\TrustedBrowserNotFoundException $exception) {
|
} catch (TrustedBrowserNotFoundException $exception) {
|
||||||
$this->logger->notice('Trusted Browser of the cookie not found.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
|
$this->logger->notice('Trusted Browser of the cookie not found.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
|
||||||
} catch (TwoFactor\Exception\TrustedBrowserPersistenceException $exception) {
|
} catch (TrustedBrowserPersistenceException $exception) {
|
||||||
$this->logger->warning('Unexpected persistence exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
|
$this->logger->warning('Unexpected persistence exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->logger->warning('Unexpected exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
|
$this->logger->warning('Unexpected exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]);
|
||||||
|
|
|
@ -25,7 +25,7 @@ use Exception;
|
||||||
|
|
||||||
class TrustedBrowserNotFoundException extends \RuntimeException
|
class TrustedBrowserNotFoundException extends \RuntimeException
|
||||||
{
|
{
|
||||||
public function __construct($message = '', Exception $previous = null)
|
public function __construct(string $message = '', Exception $previous = null)
|
||||||
{
|
{
|
||||||
parent::__construct($message, 404, $previous);
|
parent::__construct($message, 404, $previous);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ use Throwable;
|
||||||
|
|
||||||
class TrustedBrowserPersistenceException extends \RuntimeException
|
class TrustedBrowserPersistenceException extends \RuntimeException
|
||||||
{
|
{
|
||||||
public function __construct($message = "", Throwable $previous = null)
|
public function __construct(string $message = "", Throwable $previous = null)
|
||||||
{
|
{
|
||||||
parent::__construct($message, 500, $previous);
|
parent::__construct($message, 500, $previous);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ namespace Friendica\Security\TwoFactor\Repository;
|
||||||
|
|
||||||
use Friendica\Security\TwoFactor;
|
use Friendica\Security\TwoFactor;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Security\TwoFactor\Exception\TrustedBrowserNotFoundException;
|
||||||
|
use Friendica\Security\TwoFactor\Exception\TrustedBrowserPersistenceException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class TrustedBrowser
|
class TrustedBrowser
|
||||||
|
@ -50,18 +52,18 @@ class TrustedBrowser
|
||||||
*
|
*
|
||||||
* @return TwoFactor\Model\TrustedBrowser|null
|
* @return TwoFactor\Model\TrustedBrowser|null
|
||||||
*
|
*
|
||||||
* @throws TwoFactor\Exception\TrustedBrowserPersistenceException
|
* @throws TrustedBrowserPersistenceException
|
||||||
* @throws TwoFactor\Exception\TrustedBrowserNotFoundException
|
* @throws TrustedBrowserNotFoundException
|
||||||
*/
|
*/
|
||||||
public function selectOneByHash(string $cookie_hash): TwoFactor\Model\TrustedBrowser
|
public function selectOneByHash(string $cookie_hash): TwoFactor\Model\TrustedBrowser
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$fields = $this->db->selectFirst(self::$table_name, [], ['cookie_hash' => $cookie_hash]);
|
$fields = $this->db->selectFirst(self::$table_name, [], ['cookie_hash' => $cookie_hash]);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Internal server error when retrieving cookie hash \'%s\'', $cookie_hash));
|
throw new TrustedBrowserPersistenceException(sprintf('Internal server error when retrieving cookie hash \'%s\'', $cookie_hash));
|
||||||
}
|
}
|
||||||
if (!$this->db->isResult($fields)) {
|
if (!$this->db->isResult($fields)) {
|
||||||
throw new TwoFactor\Exception\TrustedBrowserNotFoundException(sprintf('Cookie hash \'%s\' not found', $cookie_hash));
|
throw new TrustedBrowserNotFoundException(sprintf('Cookie hash \'%s\' not found', $cookie_hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->factory->createFromTableRow($fields);
|
return $this->factory->createFromTableRow($fields);
|
||||||
|
@ -72,7 +74,7 @@ class TrustedBrowser
|
||||||
*
|
*
|
||||||
* @return TwoFactor\Collection\TrustedBrowsers
|
* @return TwoFactor\Collection\TrustedBrowsers
|
||||||
*
|
*
|
||||||
* @throws TwoFactor\Exception\TrustedBrowserPersistenceException
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function selectAllByUid(int $uid): TwoFactor\Collection\TrustedBrowsers
|
public function selectAllByUid(int $uid): TwoFactor\Collection\TrustedBrowsers
|
||||||
{
|
{
|
||||||
|
@ -86,7 +88,7 @@ class TrustedBrowser
|
||||||
return new TwoFactor\Collection\TrustedBrowsers($trustedBrowsers);
|
return new TwoFactor\Collection\TrustedBrowsers($trustedBrowsers);
|
||||||
|
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('selection for uid \'%s\' wasn\'t successful.', $uid));
|
throw new TrustedBrowserPersistenceException(sprintf('selection for uid \'%s\' wasn\'t successful.', $uid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,14 +97,14 @@ class TrustedBrowser
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @throws TwoFactor\Exception\TrustedBrowserPersistenceException
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function save(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool
|
public function save(TwoFactor\Model\TrustedBrowser $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);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t save trusted Browser with cookie_hash \'%s\'', $trustedBrowser->cookie_hash));
|
throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t save trusted Browser with cookie_hash \'%s\'', $trustedBrowser->cookie_hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,14 +113,14 @@ class TrustedBrowser
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @throws TwoFactor\Exception\TrustedBrowserPersistenceException
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function remove(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool
|
public function remove(TwoFactor\Model\TrustedBrowser $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]);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser with cookie hash \'%s\'', $trustedBrowser->cookie_hash));
|
throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser with cookie hash \'%s\'', $trustedBrowser->cookie_hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,14 +130,14 @@ class TrustedBrowser
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @throws TwoFactor\Exception\TrustedBrowserPersistenceException
|
* @throws TrustedBrowserPersistenceException
|
||||||
*/
|
*/
|
||||||
public function removeForUser(int $local_user, string $cookie_hash): bool
|
public function removeForUser(int $local_user, string $cookie_hash): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->db->delete(self::$table_name, ['cookie_hash' => $cookie_hash, 'uid' => $local_user]);
|
return $this->db->delete(self::$table_name, ['cookie_hash' => $cookie_hash, 'uid' => $local_user]);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser for user \'%s\' and cookie hash \'%s\'', $local_user, $cookie_hash));
|
throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser for user \'%s\' and cookie hash \'%s\'', $local_user, $cookie_hash));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +150,7 @@ class TrustedBrowser
|
||||||
try {
|
try {
|
||||||
return $this->db->delete(self::$table_name, ['uid' => $local_user]);
|
return $this->db->delete(self::$table_name, ['uid' => $local_user]);
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browsers for user \'%s\'', $local_user));
|
throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browsers for user \'%s\'', $local_user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user