Create everything required to login and register
This commit is contained in:
63
src/Controller/UserController.php
Normal file
63
src/Controller/UserController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Form\ProfileType;
|
||||
use App\Form\UserSettingsType;
|
||||
use App\Service\LastRelease;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
#[Route('/user', name: 'user')]
|
||||
class UserController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/profile', name: '_profile')]
|
||||
public function profile(
|
||||
Request $request,
|
||||
UserPasswordHasherInterface $userPasswordHasher,
|
||||
LastRelease $lastRelease,
|
||||
): Response
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$form = $this->createForm(ProfileType::class, $user);
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
if (!empty($form->get('plainPassword')->getData())) {
|
||||
if ($form->get('plainPassword')->getData() !== $form->get('plainPasswordRepeated')->getData()) {
|
||||
$this->addFlash('error', 'Password and password repeated must be the same, password not changed');
|
||||
} else {
|
||||
$this->addFlash('success', 'Password updated successfully');
|
||||
$user
|
||||
->setPassword(
|
||||
$userPasswordHasher->hashPassword(
|
||||
$user,
|
||||
$form->get('plainPassword')->getData()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->addFlash('success', 'Profile updated successfully');
|
||||
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
return $this->render('user/profile.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'release' => $lastRelease,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user