Skip to content
Snippets Groups Projects
Commit dd76f01b authored by Sebastien's avatar Sebastien
Browse files

Merge branch 'tuleap-195-declare-class-properties-only-in-constructor' into 'main'

tuleap-195-declare-class-properties-only-in-constructor

See merge request !79
parents 095e439b 0fd2242a
Branches
Tags
1 merge request!79tuleap-195-declare-class-properties-only-in-constructor
Pipeline #941 passed
...@@ -25,18 +25,11 @@ use Symfony\Contracts\Translation\TranslatorInterface; ...@@ -25,18 +25,11 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class CapsuleController extends AbstractController class CapsuleController extends AbstractController
{ {
private CapsuleRepository $capsule_repository;
private TranslatorInterface $translator;
private EntityManagerInterface $entity_manager;
public function __construct( public function __construct(
CapsuleRepository $capsule_repository, private CapsuleRepository $capsule_repository,
TranslatorInterface $translator, private TranslatorInterface $translator,
EntityManagerInterface $entity_manager private EntityManagerInterface $entity_manager
) { ) {
$this->capsule_repository = $capsule_repository;
$this->translator = $translator;
$this->entity_manager = $entity_manager;
} }
#[Route('/my_capsules', name:'capsule_list')] #[Route('/my_capsules', name:'capsule_list')]
...@@ -76,8 +69,8 @@ class CapsuleController extends AbstractController ...@@ -76,8 +69,8 @@ class CapsuleController extends AbstractController
5 5
); );
return $this->render('capsule/index.html.twig', [ return $this->renderForm('capsule/index.html.twig', [
'filterByGroupForm' => $form->createView(), 'filterByGroupForm' => $form,
'capsules' => $capsules, 'capsules' => $capsules,
'current_user' => $current_user, 'current_user' => $current_user,
'legacy_url' => $this->getParameter('app.legacy_external_prefix') 'legacy_url' => $this->getParameter('app.legacy_external_prefix')
...@@ -106,8 +99,8 @@ class CapsuleController extends AbstractController ...@@ -106,8 +99,8 @@ class CapsuleController extends AbstractController
]); ]);
} }
return $this->render('capsule/create.html.twig', [ return $this->renderForm('capsule/create.html.twig', [
'capsuleCreationForm' => $form->createView() 'capsuleCreationForm' => $form
]); ]);
} }
...@@ -161,10 +154,8 @@ class CapsuleController extends AbstractController ...@@ -161,10 +154,8 @@ class CapsuleController extends AbstractController
} }
#[Route('/capsule/delete/{id}', name:'delete_capsule')] #[Route('/capsule/delete/{id}', name:'delete_capsule')]
public function delete( public function delete(int $id, Request $request): Response
int $id, {
Request $request
): Response {
$form = $this->createForm(DeleteCapsuleFormType::class); $form = $this->createForm(DeleteCapsuleFormType::class);
$form->handleRequest($request); $form->handleRequest($request);
$current_user = $this->getUser(); $current_user = $this->getUser();
...@@ -215,8 +206,8 @@ class CapsuleController extends AbstractController ...@@ -215,8 +206,8 @@ class CapsuleController extends AbstractController
return $this->redirectToRoute('capsule_list'); return $this->redirectToRoute('capsule_list');
} }
return $this->render('capsule/delete.html.twig', [ return $this->renderForm('capsule/delete.html.twig', [
'deleteCapsuleForm' => $form->createView(), 'deleteCapsuleForm' => $form,
'capsule_name' => $capsule_name 'capsule_name' => $capsule_name
]); ]);
} }
...@@ -282,8 +273,8 @@ class CapsuleController extends AbstractController ...@@ -282,8 +273,8 @@ class CapsuleController extends AbstractController
]); ]);
} }
return $this->render('capsule/duplicate.html.twig', [ return $this->renderForm('capsule/duplicate.html.twig', [
'duplicateCapsuleForm' => $form->createView(), 'duplicateCapsuleForm' => $form,
'capsule_name' => $parent_capsule->getName() 'capsule_name' => $parent_capsule->getName()
]); ]);
} }
......
...@@ -23,30 +23,15 @@ use Symfony\Contracts\Translation\TranslatorInterface; ...@@ -23,30 +23,15 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class CapsuleEditorController extends AbstractController class CapsuleEditorController extends AbstractController
{ {
private TranslatorInterface $translator;
private MailerInterface $mailer;
private PendingEditorInvitationRepository $capsule_pending_editor_invitation_repository;
private EntityManagerInterface $entity_manager;
private UrlGeneratorInterface $urlGenerator;
private CapsuleRepository $capsule_repository;
private UserRepository $user_repository;
public function __construct( public function __construct(
MailerInterface $mailer, private MailerInterface $mailer,
TranslatorInterface $translator, private TranslatorInterface $translator,
PendingEditorInvitationRepository $capsule_pending_editor_invitation_repository, private PendingEditorInvitationRepository $capsule_pending_editor_invitation_repository,
EntityManagerInterface $entity_manager, private EntityManagerInterface $entity_manager,
UrlGeneratorInterface $urlGenerator, private UrlGeneratorInterface $urlGenerator,
CapsuleRepository $capsule_repository, private CapsuleRepository $capsule_repository,
UserRepository $user_repository private UserRepository $user_repository
) { ) {
$this->mailer = $mailer;
$this->translator = $translator;
$this->capsule_pending_editor_invitation_repository = $capsule_pending_editor_invitation_repository;
$this->entity_manager = $entity_manager;
$this->urlGenerator = $urlGenerator;
$this->capsule_repository = $capsule_repository;
$this->user_repository = $user_repository;
} }
#[Route('/capsule/{capsule_id}/editors', name:'edit_capsule_editors')] #[Route('/capsule/{capsule_id}/editors', name:'edit_capsule_editors')]
...@@ -108,8 +93,8 @@ class CapsuleEditorController extends AbstractController ...@@ -108,8 +93,8 @@ class CapsuleEditorController extends AbstractController
$pending_editors = $this->capsule_pending_editor_invitation_repository->findBy(['capsule_id' => $capsule_id]); $pending_editors = $this->capsule_pending_editor_invitation_repository->findBy(['capsule_id' => $capsule_id]);
return $this->render('capsule/editors/list_editors.html.twig', [ return $this->renderForm('capsule/editors/list_editors.html.twig', [
'userPermissionsCapsuleForm' => $form->createView(), 'userPermissionsCapsuleForm' => $form,
'capsule' => $capsule, 'capsule' => $capsule,
'editors' => $current_capsule_editors_users, 'editors' => $current_capsule_editors_users,
'pending_editors' => $pending_editors, 'pending_editors' => $pending_editors,
...@@ -280,8 +265,8 @@ class CapsuleEditorController extends AbstractController ...@@ -280,8 +265,8 @@ class CapsuleEditorController extends AbstractController
]); ]);
} }
return $this->render('capsule/editors/remove_editor.html.twig', [ return $this->renderForm('capsule/editors/remove_editor.html.twig', [
'removeEditorForm' => $form->createView(), 'removeEditorForm' => $form,
'editor_email' => $editor->getEmail(), 'editor_email' => $editor->getEmail(),
'capsule_id' => $capsule_id 'capsule_id' => $capsule_id
]); ]);
...@@ -291,7 +276,7 @@ class CapsuleEditorController extends AbstractController ...@@ -291,7 +276,7 @@ class CapsuleEditorController extends AbstractController
public function removePendingEditor( public function removePendingEditor(
int $pending_editor_invitation_id, int $pending_editor_invitation_id,
int $capsule_id, int $capsule_id,
request $request Request $request
): Response { ): Response {
$form = $this->createForm(RemoveEditorFormType::class); $form = $this->createForm(RemoveEditorFormType::class);
$form->handleRequest($request); $form->handleRequest($request);
...@@ -340,8 +325,8 @@ class CapsuleEditorController extends AbstractController ...@@ -340,8 +325,8 @@ class CapsuleEditorController extends AbstractController
]); ]);
} }
return $this->render('capsule/editors/remove_pending_editor.html.twig', [ return $this->renderForm('capsule/editors/remove_pending_editor.html.twig', [
'removeEditorForm' => $form->createView(), 'removeEditorForm' => $form,
'editor_email' => $pending_editor_invitation->getEmail(), 'editor_email' => $pending_editor_invitation->getEmail(),
'capsule_id' => $capsule_id 'capsule_id' => $capsule_id
]); ]);
......
...@@ -21,21 +21,12 @@ use Symfony\Component\Routing\Annotation\Route; ...@@ -21,21 +21,12 @@ use Symfony\Component\Routing\Annotation\Route;
class CapsuleGroupController extends AbstractController class CapsuleGroupController extends AbstractController
{ {
private TranslatorInterface $translator;
private CapsuleRepository $capsule_repository;
private EntityManagerInterface $entity_manager;
private GroupRepository $group_repository;
public function __construct( public function __construct(
TranslatorInterface $translator, private TranslatorInterface $translator,
CapsuleRepository $capsule_repository, private CapsuleRepository $capsule_repository,
EntityManagerInterface $entity_manager, private EntityManagerInterface $entity_manager,
GroupRepository $group_repository private GroupRepository $group_repository
) { ) {
$this->translator = $translator;
$this->capsule_repository = $capsule_repository;
$this->entity_manager = $entity_manager;
$this->group_repository = $group_repository;
} }
#[Route('/my_groups', name:'edit_user_groups')] #[Route('/my_groups', name:'edit_user_groups')]
...@@ -85,8 +76,8 @@ class CapsuleGroupController extends AbstractController ...@@ -85,8 +76,8 @@ class CapsuleGroupController extends AbstractController
return $this->redirectToRoute('edit_user_groups'); return $this->redirectToRoute('edit_user_groups');
} }
return $this->render('capsule/groups/create.html.twig', [ return $this->renderForm('capsule/groups/create.html.twig', [
'createCapsuleGroupsForm' => $form->createView() 'createCapsuleGroupsForm' => $form
]); ]);
} }
...@@ -132,8 +123,8 @@ class CapsuleGroupController extends AbstractController ...@@ -132,8 +123,8 @@ class CapsuleGroupController extends AbstractController
return $this->redirectToRoute('edit_user_groups'); return $this->redirectToRoute('edit_user_groups');
} }
return $this->render('capsule/groups/delete.html.twig', [ return $this->renderForm('capsule/groups/delete.html.twig', [
'deleteGroupForm' => $form->createView(), 'deleteGroupForm' => $form,
'group_name' => $group->getName() 'group_name' => $group->getName()
]); ]);
} }
...@@ -187,8 +178,8 @@ class CapsuleGroupController extends AbstractController ...@@ -187,8 +178,8 @@ class CapsuleGroupController extends AbstractController
]); ]);
} }
return $this->render('capsule/groups/capsule_groups.html.twig', [ return $this->renderForm('capsule/groups/capsule_groups.html.twig', [
'selectCapsuleGroupsForm' => $form->createView(), 'selectCapsuleGroupsForm' => $form,
'capsule' => $capsule, 'capsule' => $capsule,
'groups' => $capsule_groups_by_author, 'groups' => $capsule_groups_by_author,
'groups_not_added' => $author_capsule_groups_not_added 'groups_not_added' => $author_capsule_groups_not_added
...@@ -244,8 +235,8 @@ class CapsuleGroupController extends AbstractController ...@@ -244,8 +235,8 @@ class CapsuleGroupController extends AbstractController
]); ]);
} }
return $this->render('capsule/groups/remove.html.twig', [ return $this->renderForm('capsule/groups/remove.html.twig', [
'removeGroupForm' => $form->createView(), 'removeGroupForm' => $form,
'group_name' => $group->getName(), 'group_name' => $group->getName(),
'capsule_id' => $capsule_id 'capsule_id' => $capsule_id
]); ]);
......
...@@ -30,13 +30,13 @@ class FallbackController extends AbstractController ...@@ -30,13 +30,13 @@ class FallbackController extends AbstractController
// use iframe to enhance speed but not for creation // use iframe to enhance speed but not for creation
if (! str_starts_with($controller, 'legacy')) { if (! str_starts_with($controller, 'legacy')) {
$originalController = $request->getPathInfo(); $original_controller = $request->getPathInfo();
$originalQueryString = $request->getQueryString(); $original_query_string = $request->getQueryString();
$extension = strrchr($originalController, '.'); $extension = strrchr($original_controller, '.');
if ($extension != '.html' && $extension != '.php' && $extension != false) { if ($extension != '.html' && $extension != '.php' && $extension != false) {
//$url = "{$path_to_legacy_code}{$originalController}"; //$url = "{$path_to_legacy_code}{$originalController}";
$url = "{$originalController}"; $url = "{$original_controller}";
try { try {
$mime = LegacyHelper::getMime($url, $extension); $mime = LegacyHelper::getMime($url, $extension);
$response = new BinaryFileResponse($url); $response = new BinaryFileResponse($url);
...@@ -54,7 +54,7 @@ class FallbackController extends AbstractController ...@@ -54,7 +54,7 @@ class FallbackController extends AbstractController
$app_legacy_url_external = strval($this->getParameter('app.legacy_url_external')); $app_legacy_url_external = strval($this->getParameter('app.legacy_url_external'));
$url = "{$app_legacy_url_external}/" . $url = "{$app_legacy_url_external}/" .
"{$originalController}{$separator}?{$originalQueryString}"; "{$original_controller}{$separator}?{$original_query_string}";
$url = preg_replace('(^https?:\/\/[^/]+(:\d+)?)', '', $url); $url = preg_replace('(^https?:\/\/[^/]+(:\d+)?)', '', $url);
$pattern = '/\/+/i'; $pattern = '/\/+/i';
......
...@@ -19,11 +19,8 @@ use ZipArchive; ...@@ -19,11 +19,8 @@ use ZipArchive;
class ProjectController extends AbstractController class ProjectController extends AbstractController
{ {
private TranslatorInterface $translator; public function __construct(private TranslatorInterface $translator)
public function __construct(TranslatorInterface $translator)
{ {
$this->translator = $translator;
} }
#[Route('/project/create', name:'create_project', methods:['POST'])] #[Route('/project/create', name:'create_project', methods:['POST'])]
...@@ -225,8 +222,8 @@ class ProjectController extends AbstractController ...@@ -225,8 +222,8 @@ class ProjectController extends AbstractController
]); ]);
} }
return $this->render('project/edit_video_url.html.twig', [ return $this->renderForm('project/edit_video_url.html.twig', [
'editVideoUrlForm' => $form->createView() 'editVideoUrlForm' => $form
]); ]);
} }
} }
...@@ -24,24 +24,20 @@ use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface; ...@@ -24,24 +24,20 @@ use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
class RegistrationController extends AbstractController class RegistrationController extends AbstractController
{ {
private EmailVerifier $emailVerifier;
private RequestStack $requestStack;
private EntityManagerInterface $entity_manager;
public function __construct( public function __construct(
EmailVerifier $emailVerifier, private EmailVerifier $email_verifier,
RequestStack $requestStack, private RequestStack $request_stack,
EntityManagerInterface $entity_manager private EntityManagerInterface $entity_manager,
private CapsuleRepository $capsule_repository,
private UserRepository $user_repository,
private PendingEditorInvitationRepository $pending_editor_invitation_repository
) { ) {
$this->emailVerifier = $emailVerifier;
$this->requestStack = $requestStack;
$this->entity_manager = $entity_manager;
} }
#[Route('/register', name:'app_register')] #[Route('/register', name:'app_register')]
public function register( public function register(
Request $request, Request $request,
UserPasswordHasherInterface $userPasswordHasher UserPasswordHasherInterface $user_password_hasher
): Response { ): Response {
if ($this->getUser()) { if ($this->getUser()) {
return $this->redirectToRoute('capsule_list'); return $this->redirectToRoute('capsule_list');
...@@ -52,13 +48,13 @@ class RegistrationController extends AbstractController ...@@ -52,13 +48,13 @@ class RegistrationController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$userBuilder = new UserBuilder($userPasswordHasher, $user); $userBuilder = new UserBuilder($user_password_hasher, $user);
$this->entity_manager->persist($userBuilder->createUser()); $this->entity_manager->persist($userBuilder->createUser());
$this->entity_manager->flush(); $this->entity_manager->flush();
// generate a signed url and email it to the user // generate a signed url and email it to the user
$this->emailVerifier->sendEmailConfirmation( $this->email_verifier->sendEmailConfirmation(
'app_verify_email', 'app_verify_email',
$user->getId(), $user->getId(),
$user->getEmail(), $user->getEmail(),
...@@ -68,30 +64,25 @@ class RegistrationController extends AbstractController ...@@ -68,30 +64,25 @@ class RegistrationController extends AbstractController
->htmlTemplate('registration/confirmation_email.html.twig') ->htmlTemplate('registration/confirmation_email.html.twig')
); );
$this->requestStack->getSession()->set('userid', $user->getId()); $this->request_stack->getSession()->set('userid', $user->getId());
return $this->redirectToRoute('app_register_mail_sent'); return $this->redirectToRoute('app_register_mail_sent');
} }
return $this->render('registration/register.html.twig', [ return $this->renderForm('registration/register.html.twig', [
'registrationForm' => $form->createView(), 'registrationForm' => $form,
]); ]);
} }
#[Route('/verify/email', name:'app_verify_email')] #[Route('/verify/email', name:'app_verify_email')]
public function verifyUserEmail( public function verifyUserEmail(Request $request, TranslatorInterface $translator): Response
Request $request, {
UserRepository $userRepository,
PendingEditorInvitationRepository $pending_editor_invitation_repository,
CapsuleRepository $capsule_repository,
TranslatorInterface $translator
): Response {
$id = $request->get('id'); $id = $request->get('id');
if (null === $id) { if (null === $id) {
return $this->redirectToRoute('app_register'); return $this->redirectToRoute('app_register');
} }
$user = $userRepository->find($id); $user = $this->user_repository->find($id);
if (null === $user) { if (null === $user) {
return $this->redirectToRoute('app_register'); return $this->redirectToRoute('app_register');
...@@ -99,18 +90,14 @@ class RegistrationController extends AbstractController ...@@ -99,18 +90,14 @@ class RegistrationController extends AbstractController
// validate email confirmation link, sets User::isVerified=true and persists // validate email confirmation link, sets User::isVerified=true and persists
try { try {
$this->emailVerifier->handleEmailConfirmation($request, $user); $this->email_verifier->handleEmailConfirmation($request, $user);
} catch (VerifyEmailExceptionInterface $exception) { } catch (VerifyEmailExceptionInterface $exception) {
$this->addFlash('verify_email_error', $exception->getReason()); $this->addFlash('verify_email_error', $exception->getReason());
return $this->redirectToRoute('app_register'); return $this->redirectToRoute('app_register');
} }
$this->addCapsuleToConfirmedPreviousPendingEditor( $this->addCapsuleToConfirmedPreviousPendingEditor($user);
$user,
$pending_editor_invitation_repository,
$capsule_repository
);
$this->addFlash( $this->addFlash(
'email_verified_success', 'email_verified_success',
...@@ -121,10 +108,10 @@ class RegistrationController extends AbstractController ...@@ -121,10 +108,10 @@ class RegistrationController extends AbstractController
} }
#[Route('/register_mail_sent', name:'app_register_mail_sent')] #[Route('/register_mail_sent', name:'app_register_mail_sent')]
public function mailSentMessage(UserRepository $userRepository): Response public function mailSentMessage(): Response
{ {
$userid = $this->requestStack->getSession()->get('userid'); $user_id = $this->request_stack->getSession()->get('userid');
$user = $userRepository->find($userid); $user = $this->user_repository->find($user_id);
return $this->render( return $this->render(
'registration/register_mail_sent.html.twig', 'registration/register_mail_sent.html.twig',
...@@ -132,19 +119,18 @@ class RegistrationController extends AbstractController ...@@ -132,19 +119,18 @@ class RegistrationController extends AbstractController
); );
} }
private function addCapsuleToConfirmedPreviousPendingEditor( private function addCapsuleToConfirmedPreviousPendingEditor(User $user): void
User $user, {
PendingEditorInvitationRepository $pending_editor_invitation_repository, $pending_editor_invitations = $this->pending_editor_invitation_repository->findBy(
CapsuleRepository $capsule_repository ['email' => $user->getEmail()]
): void { );
$pending_editor_invitations = $pending_editor_invitation_repository->findBy(['email' => $user->getEmail()]);
if ($pending_editor_invitations == null) { if (! is_array($pending_editor_invitations)) {
return; return;
} }
$capsules_ids = $this->removeInvitations($pending_editor_invitations); $capsules_ids = $this->removeInvitations($pending_editor_invitations);
$this->addEditorToCapsules($capsules_ids, $user, $capsule_repository); $this->addEditorToCapsules($capsules_ids, $user);
} }
/** /**
...@@ -169,12 +155,9 @@ class RegistrationController extends AbstractController ...@@ -169,12 +155,9 @@ class RegistrationController extends AbstractController
/** /**
* @param array<int> $capsules_ids * @param array<int> $capsules_ids
*/ */
private function addEditorToCapsules( private function addEditorToCapsules(array $capsules_ids, User $user): void
array $capsules_ids, {
User $user, $capsules = $this->capsule_repository->findBy(['id' => $capsules_ids]);
CapsuleRepository $capsule_repository
): void {
$capsules = $capsule_repository->findBy(['id' => $capsules_ids]);
foreach ($capsules as $capsule) { foreach ($capsules as $capsule) {
if (! $capsule instanceof Capsule) { if (! $capsule instanceof Capsule) {
......
...@@ -23,15 +23,10 @@ class ResetPasswordController extends AbstractController ...@@ -23,15 +23,10 @@ class ResetPasswordController extends AbstractController
{ {
use ResetPasswordControllerTrait; use ResetPasswordControllerTrait;
private ResetPasswordHelperInterface $resetPasswordHelper;
private EntityManagerInterface $entityManager;
public function __construct( public function __construct(
ResetPasswordHelperInterface $resetPasswordHelper, private ResetPasswordHelperInterface $reset_password_helper,
EntityManagerInterface $entityManager private EntityManagerInterface $entity_manager
) { ) {
$this->resetPasswordHelper = $resetPasswordHelper;
$this->entityManager = $entityManager;
} }
#[Route('', name:'app_forgot_password_request')] #[Route('', name:'app_forgot_password_request')]
...@@ -47,8 +42,8 @@ class ResetPasswordController extends AbstractController ...@@ -47,8 +42,8 @@ class ResetPasswordController extends AbstractController
); );
} }
return $this->render('reset_password/request.html.twig', [ return $this->renderForm('reset_password/request.html.twig', [
'requestForm' => $form->createView(), 'requestForm' => $form,
]); ]);
} }
...@@ -57,19 +52,19 @@ class ResetPasswordController extends AbstractController ...@@ -57,19 +52,19 @@ class ResetPasswordController extends AbstractController
{ {
// Generate a fake token if the user does not exist or someone hit this page directly. // Generate a fake token if the user does not exist or someone hit this page directly.
// This prevents exposing whether or not a user was found with the given email address or not // This prevents exposing whether or not a user was found with the given email address or not
if (null === ($resetToken = $this->getTokenObjectFromSession())) { if (null === ($reset_token = $this->getTokenObjectFromSession())) {
$resetToken = $this->resetPasswordHelper->generateFakeResetToken(); $reset_token = $this->reset_password_helper->generateFakeResetToken();
} }
return $this->render('reset_password/check_email.html.twig', [ return $this->render('reset_password/check_email.html.twig', [
'resetToken' => $resetToken, 'resetToken' => $reset_token,
]); ]);
} }
#[Route('/reset/{token}', name:'app_reset_password')] #[Route('/reset/{token}', name:'app_reset_password')]
public function reset( public function reset(
Request $request, Request $request,
UserPasswordHasherInterface $userPasswordHasher, UserPasswordHasherInterface $user_password_hasher,
string $token = null string $token = null
): Response { ): Response {
if ($token) { if ($token) {
...@@ -86,7 +81,7 @@ class ResetPasswordController extends AbstractController ...@@ -86,7 +81,7 @@ class ResetPasswordController extends AbstractController
} }
try { try {
$user = $this->resetPasswordHelper->validateTokenAndFetchUser($token); $user = $this->reset_password_helper->validateTokenAndFetchUser($token);
if (! $user instanceof User) { if (! $user instanceof User) {
throw new \Exception("User should be an instance of UserPasswordHasherInterface"); throw new \Exception("User should be an instance of UserPasswordHasherInterface");
} }
...@@ -105,16 +100,16 @@ class ResetPasswordController extends AbstractController ...@@ -105,16 +100,16 @@ class ResetPasswordController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
// A password reset token should be used only once, remove it. // A password reset token should be used only once, remove it.
$this->resetPasswordHelper->removeResetRequest($token); $this->reset_password_helper->removeResetRequest($token);
// Encode(hash) the plain password, and set it. // Encode(hash) the plain password, and set it.
$encodedPassword = $userPasswordHasher->hashPassword( $encoded_password = $user_password_hasher->hashPassword(
$user, $user,
$form->get('plainPassword')->getData() $form->get('plainPassword')->getData()
); );
$user->setPassword($encodedPassword); $user->setPassword($encoded_password);
$this->entityManager->flush(); $this->entity_manager->flush();
// The session is cleaned up after the password has been changed. // The session is cleaned up after the password has been changed.
$this->cleanSessionAfterReset(); $this->cleanSessionAfterReset();
...@@ -122,15 +117,17 @@ class ResetPasswordController extends AbstractController ...@@ -122,15 +117,17 @@ class ResetPasswordController extends AbstractController
return $this->redirectToRoute('app_login'); return $this->redirectToRoute('app_login');
} }
return $this->render('reset_password/reset.html.twig', [ return $this->renderForm('reset_password/reset.html.twig', [
'resetForm' => $form->createView(), 'resetForm' => $form,
]); ]);
} }
private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer): RedirectResponse private function processSendingPasswordResetEmail(
{ string $email_form_data,
$user = $this->entityManager->getRepository(User::class)->findOneBy([ MailerInterface $mailer
'email' => $emailFormData, ): RedirectResponse {
$user = $this->entity_manager->getRepository(User::class)->findOneBy([
'email' => $email_form_data,
]); ]);
// Do not reveal whether a user account was found or not. // Do not reveal whether a user account was found or not.
...@@ -139,7 +136,7 @@ class ResetPasswordController extends AbstractController ...@@ -139,7 +136,7 @@ class ResetPasswordController extends AbstractController
} }
try { try {
$resetToken = $this->resetPasswordHelper->generateResetToken($user); $resetToken = $this->reset_password_helper->generateResetToken($user);
} catch (ResetPasswordExceptionInterface $e) { } catch (ResetPasswordExceptionInterface $e) {
return $this->redirectToRoute('app_check_email'); return $this->redirectToRoute('app_check_email');
} }
......
...@@ -10,21 +10,21 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; ...@@ -10,21 +10,21 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController class SecurityController extends AbstractController
{ {
#[Route('/login', name:'app_login')] #[Route('/login', name:'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response public function login(AuthenticationUtils $authentication_utils): Response
{ {
if ($this->getUser()) { if ($this->getUser()) {
return $this->redirectToRoute('capsule_list'); return $this->redirectToRoute('capsule_list');
} }
// get the login error if there is one // get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError(); $error = $authentication_utils->getLastAuthenticationError();
// last username entered by the user // last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername(); $last_username = $authentication_utils->getLastUsername();
return $this->render( return $this->render(
'security/login.html.twig', 'security/login.html.twig',
[ [
'last_username' => $lastUsername, 'last_username' => $last_username,
'error' => $error 'error' => $error
] ]
); );
......
...@@ -15,6 +15,12 @@ use Symfony\Contracts\Translation\TranslatorInterface; ...@@ -15,6 +15,12 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class UserController extends AbstractController class UserController extends AbstractController
{ {
public function __construct(
private EntityManagerInterface $entity_manager,
private TranslatorInterface $translator
) {
}
#[Route('/profile', name:'show_profile')] #[Route('/profile', name:'show_profile')]
public function showProfile(): Response public function showProfile(): Response
{ {
...@@ -30,11 +36,8 @@ class UserController extends AbstractController ...@@ -30,11 +36,8 @@ class UserController extends AbstractController
} }
#[Route('/edit_profile', name:'edit_profile')] #[Route('/edit_profile', name:'edit_profile')]
public function editProfile( public function editProfile(Request $request): Response
Request $request, {
EntityManagerInterface $entity_manager,
TranslatorInterface $translator
): Response {
$current_user = $this->getUser(); $current_user = $this->getUser();
if (! $current_user instanceof User) { if (! $current_user instanceof User) {
...@@ -47,28 +50,26 @@ class UserController extends AbstractController ...@@ -47,28 +50,26 @@ class UserController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$entity_manager->persist($current_user); $this->entity_manager->persist($current_user);
$entity_manager->flush(); $this->entity_manager->flush();
$this->addFlash( $this->addFlash(
'profile_updated_success', 'profile_updated_success',
$translator->trans('user.profile.updated_success') $this->translator->trans('user.profile.updated_success')
); );
return $this->redirectToRoute('show_profile'); return $this->redirectToRoute('show_profile');
} }
return $this->render('user/edit_profile.html.twig', [ return $this->renderForm('user/edit_profile.html.twig', [
'editUserProfileForm' => $form->createView() 'editUserProfileForm' => $form
]); ]);
} }
#[Route('/edit_password', name:'edit_password')] #[Route('/edit_password', name:'edit_password')]
public function editPassword( public function editPassword(
Request $request, Request $request,
UserPasswordHasherInterface $userPasswordHasher, UserPasswordHasherInterface $user_password_hasher,
EntityManagerInterface $entity_manager,
TranslatorInterface $translator
): Response { ): Response {
$form = $this->createForm(EditPasswordFormType::class); $form = $this->createForm(EditPasswordFormType::class);
$form->handleRequest($request); $form->handleRequest($request);
...@@ -78,23 +79,23 @@ class UserController extends AbstractController ...@@ -78,23 +79,23 @@ class UserController extends AbstractController
return $this->redirectToRoute('app_logout'); return $this->redirectToRoute('app_logout');
} }
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$encodedPassword = $userPasswordHasher->hashPassword( $encodedPassword = $user_password_hasher->hashPassword(
$current_user, $current_user,
$form->get('plainPassword')->getData() $form->get('plainPassword')->getData()
); );
$current_user->setPassword($encodedPassword); $current_user->setPassword($encodedPassword);
$entity_manager->flush(); $this->entity_manager->flush();
$this->addFlash( $this->addFlash(
'profile_updated_success', 'profile_updated_success',
$translator->trans('user.password.updated_success') $this->translator->trans('user.password.updated_success')
); );
return $this->redirectToRoute('show_profile'); return $this->redirectToRoute('show_profile');
} }
return $this->render('user/edit_password.html.twig', [ return $this->renderForm('user/edit_password.html.twig', [
'editPasswordForm' => $form->createView() 'editPasswordForm' => $form
]); ]);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment