This commit is contained in:
1 parent
f15d9a9cfd
commit
054e970df9
36 files changed
+1434
-363
No files matched your search
@@ -7,18 +7,26 @@ use App\Form\ProfileFormType;
|
||||
use App\Form\ChangePasswordFormType;
|
||||
use App\Repository\ReviewRepository;
|
||||
use App\Repository\AlbumRepository;
|
||||
use App\Service\ImageStorage;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Bundle\SecurityBundle\Attribute\IsGranted;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
/**
|
||||
* AccountController hosts authenticated self-service pages.
|
||||
*/
|
||||
#[IsGranted('ROLE_USER')]
|
||||
class AccountController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Summarizes the signed-in user's recent activity.
|
||||
*/
|
||||
#[Route('/dashboard', name: 'account_dashboard', methods: ['GET'])]
|
||||
public function dashboard(ReviewRepository $reviews, AlbumRepository $albums): Response
|
||||
{
|
||||
@@ -50,6 +58,7 @@ class AccountController extends AbstractController
|
||||
return $this->render('account/dashboard.html.twig', [
|
||||
'email' => $user->getEmail(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
'profileImage' => $user->getProfileImagePath(),
|
||||
'reviewCount' => $reviewCount,
|
||||
'albumCount' => $albumCount,
|
||||
'userType' => $userType,
|
||||
@@ -58,12 +67,59 @@ class AccountController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows users to update profile details and avatar.
|
||||
*/
|
||||
#[Route('/account/profile', name: 'account_profile', methods: ['GET', 'POST'])]
|
||||
public function profile(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $hasher, ImageStorage $images): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$form = $this->createForm(ProfileFormType::class, $user);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$newPassword = (string) $form->get('newPassword')->getData();
|
||||
if ($newPassword !== '') {
|
||||
$current = (string) $form->get('currentPassword')->getData();
|
||||
if ($current === '' || !$hasher->isPasswordValid($user, $current)) {
|
||||
$form->get('currentPassword')->addError(new FormError('Current password is incorrect.'));
|
||||
return $this->render('account/profile.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
$user->setPassword($hasher->hashPassword($user, $newPassword));
|
||||
}
|
||||
|
||||
$upload = $form->get('profileImage')->getData();
|
||||
if ($upload instanceof UploadedFile) {
|
||||
$images->remove($user->getProfileImagePath());
|
||||
$user->setProfileImagePath($images->storeProfileImage($upload));
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'Profile updated.');
|
||||
return $this->redirectToRoute('account_profile');
|
||||
}
|
||||
|
||||
return $this->render('account/profile.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'profileImage' => $user->getProfileImagePath(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows account-level settings options.
|
||||
*/
|
||||
#[Route('/settings', name: 'account_settings', methods: ['GET'])]
|
||||
public function settings(): Response
|
||||
{
|
||||
return $this->render('account/settings.html.twig');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the password change form and updates the hash.
|
||||
*/
|
||||
#[Route('/account/password', name: 'account_password', methods: ['GET', 'POST'])]
|
||||
public function changePassword(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $hasher): Response
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user