Implement changing of user password
This commit is contained in:
parent
9b3c970bba
commit
b8c6d41dc9
3 changed files with 51 additions and 50 deletions
|
@ -5,6 +5,7 @@ namespace App\Controller;
|
|||
use App\Entity\Wish;
|
||||
use App\Entity\User;
|
||||
use App\Form\WishFormType;
|
||||
use App\Form\ChangePasswordFormType;
|
||||
|
||||
use App\Repository\OfferingRepository;
|
||||
use App\Repository\WishRepository;
|
||||
|
@ -14,7 +15,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
use Twig\Environment;
|
||||
|
||||
class UserController extends AbstractController
|
||||
|
@ -27,7 +30,7 @@ class UserController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/user', name: 'user_page')]
|
||||
public function user(OfferingRepository $offeringRepository): Response
|
||||
public function user(OfferingRepository $offeringRepository, Request $request, UserPasswordHasherInterface $passwordEncoder): Response
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
|
@ -36,9 +39,27 @@ class UserController extends AbstractController
|
|||
$this->addFlash('error','Your email is not verified, please check your inbox');
|
||||
}
|
||||
|
||||
$form = $this->createForm(ChangePasswordFormType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$user->setPassword(
|
||||
$passwordEncoder->hashPassword(
|
||||
$user,
|
||||
$form->get('plainPassword')->getData()
|
||||
)
|
||||
);
|
||||
|
||||
$entityManager = $this->getDoctrine()->getManager();
|
||||
$entityManager->persist($user);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->addFlash("success", "Successfully changed the password!");
|
||||
}
|
||||
|
||||
return $this->render('user/index.html.twig', [
|
||||
'user' => $user,
|
||||
'offers' => $offeringRepository->findByUser($user),
|
||||
'changePassword_form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue