This commit is contained in:
1 parent
054e970df9
commit
1c98a634c3
50 files changed
+1666
-593
No files matched your search
@@ -4,7 +4,6 @@ namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\ProfileFormType;
|
||||
use App\Form\ChangePasswordFormType;
|
||||
use App\Repository\ReviewRepository;
|
||||
use App\Repository\AlbumRepository;
|
||||
use App\Service\ImageStorage;
|
||||
@@ -42,7 +41,13 @@ class AccountController extends AbstractController
|
||||
->where('a.source = :src')->setParameter('src', 'user')
|
||||
->andWhere('a.createdBy = :u')->setParameter('u', $user)
|
||||
->getQuery()->getSingleScalarResult();
|
||||
$userType = $this->isGranted('ROLE_ADMIN') ? 'Admin' : 'User';
|
||||
if ($this->isGranted('ROLE_ADMIN')) {
|
||||
$userType = 'Admin';
|
||||
} elseif ($this->isGranted('ROLE_MODERATOR')) {
|
||||
$userType = 'Moderator';
|
||||
} else {
|
||||
$userType = 'User';
|
||||
}
|
||||
$userReviews = $reviews->createQueryBuilder('r')
|
||||
->where('r.author = :u')->setParameter('u', $user)
|
||||
->orderBy('r.createdAt', 'DESC')
|
||||
@@ -84,9 +89,10 @@ class AccountController extends AbstractController
|
||||
$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(),
|
||||
]);
|
||||
return $this->render('account/profile.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'profileImage' => $user->getProfileImagePath(),
|
||||
]);
|
||||
}
|
||||
$user->setPassword($hasher->hashPassword($user, $newPassword));
|
||||
}
|
||||
@@ -116,35 +122,6 @@ class AccountController extends AbstractController
|
||||
{
|
||||
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
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$form = $this->createForm(ChangePasswordFormType::class);
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$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/password.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
$newPassword = (string) $form->get('newPassword')->getData();
|
||||
$user->setPassword($hasher->hashPassword($user, $newPassword));
|
||||
$em->flush();
|
||||
$this->addFlash('success', 'Password updated.');
|
||||
return $this->redirectToRoute('account_dashboard');
|
||||
}
|
||||
return $this->render('account/password.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user