mirror of
https://github.com/friendica/friendica
synced 2025-04-24 01:50:17 +00:00
UserSession class [6] - Refactor src/Module/ files without DI
This commit is contained in:
parent
bf39b5a948
commit
22198ea495
8 changed files with 74 additions and 38 deletions
|
@ -26,8 +26,8 @@ use Friendica\BaseModule;
|
|||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Session\Capability\IHandleSessions;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Util\Profiler;
|
||||
use PragmaRX\Google2FA\Google2FA;
|
||||
|
@ -47,18 +47,21 @@ class Verify extends BaseModule
|
|||
protected $session;
|
||||
/** @var IManagePersonalConfigValues */
|
||||
protected $pConfig;
|
||||
/** @var IHandleUserSessions */
|
||||
protected $userSession;
|
||||
|
||||
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManagePersonalConfigValues $pConfig, IHandleSessions $session, array $server, array $parameters = [])
|
||||
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManagePersonalConfigValues $pConfig, IHandleSessions $session, IHandleUserSessions $userSession, $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->session = $session;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->session = $session;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->userSession = $userSession;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!$this->userSession->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -67,7 +70,7 @@ class Verify extends BaseModule
|
|||
|
||||
$code = $request['verify_code'] ?? '';
|
||||
|
||||
$valid = (new Google2FA())->verifyKey($this->pConfig->get(Session::getLocalUser(), '2fa', 'secret'), $code);
|
||||
$valid = (new Google2FA())->verifyKey($this->pConfig->get($this->userSession->getLocalUserId(), '2fa', 'secret'), $code);
|
||||
|
||||
// The same code can't be used twice even if it's valid
|
||||
if ($valid && $this->session->get('2fa') !== $code) {
|
||||
|
@ -82,7 +85,7 @@ class Verify extends BaseModule
|
|||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!$this->userSession->getLocalUserId()) {
|
||||
$this->baseUrl->redirect();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue