[TOOLS] Cleanup PHPStan warnings

This commit is contained in:
2021-12-01 12:07:43 +00:00
committed by Diogo Peralta Cordeiro
parent 0b57b20d38
commit d58483a6ca
5 changed files with 85 additions and 63 deletions

View File

@@ -11,6 +11,7 @@ use function App\Core\I18n\_m;
use App\Entity\LocalUser;
use App\Security\EmailVerifier;
use App\Util\Exception\ClientException;
use App\Util\Exception\NotImplementedException;
use App\Util\Exception\RedirectException;
use App\Util\Form\FormFields;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
@@ -36,20 +37,21 @@ class ResetPassword extends Controller
*/
public function requestPasswordReset(Request $request)
{
$form = Form::create([
['email', EmailType::class, ['label' => _m('Email'), 'constraints' => [new NotBlank(['message' => _m('Please enter an email')])]]],
['password_reset_request', SubmitType::class, ['label' => _m('Submit request')]],
]);
throw new NotImplementedException;
// $form = Form::create([
// ['email', EmailType::class, ['label' => _m('Email'), 'constraints' => [new NotBlank(['message' => _m('Please enter an email')])]]],
// ['password_reset_request', SubmitType::class, ['label' => _m('Submit request')]],
// ]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
return EmailVerifier::processSendingPasswordResetEmail($form->get('email')->getData(), $this);
}
// $form->handleRequest($request);
// if ($form->isSubmitted() && $form->isValid()) {
// return EmailVerifier::processSendingPasswordResetEmail($form->get('email')->getData(), $this);
// }
return [
'_template' => 'reset_password/request.html.twig',
'password_reset_form' => $form->createView(),
];
// return [
// '_template' => 'reset_password/request.html.twig',
// 'password_reset_form' => $form->createView(),
// ];
}
/**
@@ -57,15 +59,17 @@ class ResetPassword extends Controller
*/
public function checkEmail()
{
// We prevent users from directly accessing this page
if (null === ($resetToken = $this->getTokenObjectFromSession())) {
throw new RedirectException('request_reset_password');
}
throw new NotImplementedException;
return [
'_template' => 'reset_password/check_email.html.twig',
'resetToken' => $resetToken,
];
// // We prevent users from directly accessing this page
// if (null === ($resetToken = $this->getTokenObjectFromSession())) {
// throw new RedirectException('request_reset_password');
// }
// return [
// '_template' => 'reset_password/check_email.html.twig',
// 'resetToken' => $resetToken,
// ];
}
/**
@@ -73,53 +77,57 @@ class ResetPassword extends Controller
*/
public function reset(Request $request, ?string $token = null)
{
if ($token) {
// We store the token in session and remove it from the URL, to avoid the URL being
// loaded in a browser and potentially leaking the token to 3rd party JavaScript.
$this->storeTokenInSession($token);
throw new RedirectException('reset_password');
}
throw new NotImplementedException;
$token = $this->getTokenFromSession();
if (null === $token) {
throw new ClientException(_m('No reset password token found in the URL or in the session'));
}
// if ($token) {
// // We store the token in session and remove it from the URL, to avoid the URL being
// // loaded in a browser and potentially leaking the token to 3rd party JavaScript.
// $this->storeTokenInSession($token);
// throw new RedirectException('reset_password');
// }
try {
$user = EmailVerifier::validateTokenAndFetchUser($token);
} catch (ResetPasswordExceptionInterface $e) {
$this->addFlash('reset_password_error', _m('There was a problem validating your reset request - {reason}', ['reason' => $e->getReason()]));
throw new RedirectException('request_reset_password');
}
// $token = $this->getTokenFromSession();
// if (null === $token) {
// throw new ClientException(_m('No reset password token found in the URL or in the session'));
// }
// The token is valid; allow the user to change their password.
$form = Form::create([
FormFields::repeated_password(),
['password_reset', SubmitType::class, ['label' => _m('Change password')]],
]);
// try {
// $user = EmailVerifier::validateTokenAndFetchUser($token);
// } catch (ResetPasswordExceptionInterface $e) {
// $this->addFlash('reset_password_error', _m('There was a problem validating your reset request - {reason}', ['reason' => $e->getReason()]));
// throw new RedirectException('request_reset_password');
// }
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// A password reset token should be used only once, remove it.
EmailVerifier::removeResetRequest($token);
// // The token is valid; allow the user to change their password.
// $form = Form::create([
// FormFields::repeated_password(),
// ['password_reset', SubmitType::class, ['label' => _m('Change password')]],
// ]);
$user->setPassword(LocalUser::hashPassword($form->get('password')->getData()));
DB::flush();
// $form->handleRequest($request);
// if ($form->isSubmitted() && $form->isValid()) {
// // A password reset token should be used only once, remove it.
// EmailVerifier::removeResetRequest($token);
// The session is cleaned up after the password has been changed.
$this->cleanSessionAfterReset();
// $user->setPassword(LocalUser::hashPassword($form->get('password')->getData()));
// DB::flush();
throw new RedirectException('main_all');
}
// // The session is cleaned up after the password has been changed.
// $this->cleanSessionAfterReset();
return [
'_template' => 'reset_password/reset.html.twig',
'resetForm' => $form->createView(),
];
// throw new RedirectException('main_all');
// }
// return [
// '_template' => 'reset_password/reset.html.twig',
// 'resetForm' => $form->createView(),
// ];
}
public function setInSession(ResetPasswordToken $reset_token)
{
$this->setTokenObjectInSession($reset_token);
throw new NotImplementedException;
// $this->setTokenObjectInSession($reset_token);
}
}