mirror of
https://github.com/friendica/friendica
synced 2025-04-19 09:10:12 +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
|
@ -24,7 +24,7 @@ namespace Friendica\Module\Security;
|
|||
use Friendica\App;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Response;
|
||||
|
@ -36,12 +36,15 @@ class PasswordTooLong extends \Friendica\BaseModule
|
|||
{
|
||||
/** @var SystemMessages */
|
||||
private $sysmsg;
|
||||
/** @var IHandleUserSessions */
|
||||
private $userSession;
|
||||
|
||||
public function __construct(SystemMessages $sysmsg, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
public function __construct(SystemMessages $sysmsg, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->sysmsg = $sysmsg;
|
||||
$this->sysmsg = $sysmsg;
|
||||
$this->userSession = $userSession;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
|
@ -55,13 +58,13 @@ class PasswordTooLong extends \Friendica\BaseModule
|
|||
}
|
||||
|
||||
// check if the old password was supplied correctly before changing it to the new value
|
||||
User::getIdFromPasswordAuthentication(Session::getLocalUser(), $request['password_current']);
|
||||
User::getIdFromPasswordAuthentication($this->userSession->getLocalUserId(), $request['password_current']);
|
||||
|
||||
if (strlen($request['password_current']) <= 72) {
|
||||
throw new \Exception($this->l10n->t('Password does not need changing.'));
|
||||
}
|
||||
|
||||
$result = User::updatePassword(Session::getLocalUser(), $newpass);
|
||||
$result = User::updatePassword($this->userSession->getLocalUserId(), $newpass);
|
||||
if (!DBA::isResult($result)) {
|
||||
throw new \Exception($this->l10n->t('Password update failed. Please try again.'));
|
||||
}
|
||||
|
|
|
@ -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