Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2022-03-21 11:49:45 +0300
committerThomas Citharel <tcit@tcit.fr>2022-06-10 17:41:41 +0300
commitabe5ff365437927ee9ee9411d71c2e9aa23c4eb7 (patch)
tree514ae9138bff15b0ae37b934909b36e46e2bf5b6 /core/Controller
parent6283d14fa69562867608d7a3fa7a2e60b27f24ac (diff)
Make LostController use IInitialState and LoggerInterfaceadd-password-reset-typed-events
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'core/Controller')
-rw-r--r--core/Controller/LostController.php30
1 files changed, 15 insertions, 15 deletions
diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php
index 4d15fc9887e..0172d94ac95 100644
--- a/core/Controller/LostController.php
+++ b/core/Controller/LostController.php
@@ -35,6 +35,7 @@
*/
namespace OC\Core\Controller;
+use Exception;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Core\Events\BeforePasswordResetEvent;
use OC\Core\Events\PasswordResetEvent;
@@ -42,13 +43,13 @@ use OC\Core\Exception\ResetPasswordException;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Services\IInitialState;
use OCP\Defaults;
use OCP\Encryption\IEncryptionModule;
use OCP\Encryption\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\HintException;
use OCP\IConfig;
-use OCP\IInitialStateService;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IURLGenerator;
@@ -80,9 +81,8 @@ class LostController extends Controller {
protected IMailer $mailer;
private LoggerInterface $logger;
private Manager $twoFactorManager;
- private IInitialStateService $initialStateService;
+ private IInitialState $initialState;
private IVerificationToken $verificationToken;
-
private IEventDispatcher $eventDispatcher;
public function __construct(
@@ -93,12 +93,12 @@ class LostController extends Controller {
Defaults $defaults,
IL10N $l10n,
IConfig $config,
- $defaultMailAddress,
+ string $defaultMailAddress,
IManager $encryptionManager,
IMailer $mailer,
LoggerInterface $logger,
Manager $twoFactorManager,
- IInitialStateService $initialStateService,
+ IInitialState $initialState,
IVerificationToken $verificationToken,
IEventDispatcher $eventDispatcher
) {
@@ -113,7 +113,7 @@ class LostController extends Controller {
$this->mailer = $mailer;
$this->logger = $logger;
$this->twoFactorManager = $twoFactorManager;
- $this->initialStateService = $initialStateService;
+ $this->initialState = $initialState;
$this->verificationToken = $verificationToken;
$this->eventDispatcher = $eventDispatcher;
}
@@ -127,7 +127,7 @@ class LostController extends Controller {
public function resetform(string $token, string $userId): TemplateResponse {
try {
$this->checkPasswordResetToken($token, $userId);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
if ($this->config->getSystemValue('lost_password_link', '') !== 'disabled'
|| ($e instanceof InvalidTokenException
&& !in_array($e->getCode(), [InvalidTokenException::TOKEN_NOT_FOUND, InvalidTokenException::USER_UNKNOWN]))
@@ -145,8 +145,8 @@ class LostController extends Controller {
TemplateResponse::RENDER_AS_GUEST
);
}
- $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId);
- $this->initialStateService->provideInitialState('core', 'resetPasswordTarget',
+ $this->initialState->provideInitialState('resetPasswordUser', $userId);
+ $this->initialState->provideInitialState('resetPasswordTarget',
$this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', ['userId' => $userId, 'token' => $token])
);
@@ -159,7 +159,7 @@ class LostController extends Controller {
}
/**
- * @throws \Exception
+ * @throws Exception
*/
protected function checkPasswordResetToken(string $token, string $userId): void {
try {
@@ -169,7 +169,7 @@ class LostController extends Controller {
$error = $e->getCode() === InvalidTokenException::TOKEN_EXPIRED
? $this->l10n->t('Could not reset password because the token is expired')
: $this->l10n->t('Could not reset password because the token is invalid');
- throw new \Exception($error, (int)$e->getCode(), $e);
+ throw new Exception($error, (int)$e->getCode(), $e);
}
}
@@ -203,7 +203,7 @@ class LostController extends Controller {
} catch (ResetPasswordException $e) {
// Ignore the error since we do not want to leak this info
$this->logger->warning('Could not send password reset email: ' . $e->getMessage());
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
@@ -236,7 +236,7 @@ class LostController extends Controller {
\OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]);
if (!$user->setPassword($password)) {
- throw new \Exception();
+ throw new Exception();
}
$this->eventDispatcher->dispatchTyped(new PasswordResetEvent($user, $password));
@@ -248,7 +248,7 @@ class LostController extends Controller {
@\OC::$server->getUserSession()->unsetMagicInCookie();
} catch (HintException $e) {
return $this->error($e->getHint());
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return $this->error($e->getMessage());
}
@@ -301,7 +301,7 @@ class LostController extends Controller {
$message->setFrom([$this->from => $this->defaults->getName()]);
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
// Log the exception and continue
$this->logger->error($e->getMessage(), ['app' => 'core', 'exception' => $e]);
}