Use uniqid for wishes and users

This commit is contained in:
Jannis Portmann 2022-01-17 21:25:31 +01:00
parent ee063cd439
commit 946b30b486
10 changed files with 77 additions and 9 deletions

View file

@ -33,6 +33,7 @@ class RegistrationController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user->setUrlId(uniqid());
// encode the plain password
$user->setPassword(
$passwordEncoder->hashPassword(

View file

@ -19,7 +19,7 @@ use Symfony\Component\Routing\Annotation\Route;
class TradeController extends AbstractController
{
#[Route('/trade/{id}', name: 'trade')]
#[Route('/trade/{urlId}', name: 'trade')]
public function sendEmail(MailerInterface $mailer, Offering $offer, OfferingRepository $offeringRepository, WishRepository $wishRepository): Response
{
$user = $this->getUser();
@ -35,7 +35,7 @@ class TradeController extends AbstractController
->htmlTemplate('user/trade/offer_email.html.twig')
->context([
'user' => $user,
'id' => $user->getId(),
'urlId' => $user->getUrlId(),
])
;
try
@ -49,6 +49,6 @@ class TradeController extends AbstractController
$this->addFlash('error','You can\'t trade with yourself!');
}
return $this->redirectToRoute('show_offer', ['urlId' => $offer->getId()]);
return $this->redirectToRoute('show_offer', ['urlId' => $offer->getUrlId()]);
}
}

View file

@ -53,7 +53,7 @@ class UserController extends AbstractController
]);
}
#[Route('/user/{id}', name: 'user_public')]
#[Route('/user/{urlId}', name: 'user_public')]
public function show_user(User $user, OfferingRepository $offeringRepository, WishRepository $wishRepository): Response
{
return $this->render('user/public.html.twig', [
@ -89,7 +89,7 @@ class UserController extends AbstractController
]);
}
#[Route('/wish/delete/{id}', name: 'delete_wish')]
#[Route('/wish/delete/{urlId}', name: 'delete_wish')]
public function deleteWish(Wish $wish): Response
{
$user = $this->getUser();

View file

@ -65,6 +65,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
*/
private $zipCode;
/**
* @ORM\Column(type="string", length=13)
*/
private $urlId;
public function __construct()
{
$this->offerings = new ArrayCollection();
@ -255,4 +260,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this;
}
public function getUrlId(): ?string
{
return $this->urlId;
}
public function setUrlId(string $urlId): self
{
$this->urlId = $urlId;
return $this;
}
}

View file

@ -27,6 +27,11 @@ class Wish
*/
private $byUser;
/**
* @ORM\Column(type="string", length=13)
*/
private $urlId;
public function getId(): ?int
{
return $this->id;
@ -60,4 +65,16 @@ class Wish
{
return (string) $this->getTitle();
}
public function getUrlId(): ?string
{
return $this->urlId;
}
public function setUrlId(string $urlId): self
{
$this->urlId = $urlId;
return $this;
}
}