Use uniqid for wishes and users
This commit is contained in:
		
							parent
							
								
									ee063cd439
								
							
						
					
					
						commit
						946b30b486
					
				
					 10 changed files with 77 additions and 9 deletions
				
			
		
							
								
								
									
										33
									
								
								migrations/Version20220117193804.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								migrations/Version20220117193804.php
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,33 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare(strict_types=1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace DoctrineMigrations;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Doctrine\DBAL\Schema\Schema;
 | 
				
			||||||
 | 
					use Doctrine\Migrations\AbstractMigration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Auto-generated Migration: Please modify to your needs!
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					final class Version20220117193804 extends AbstractMigration
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function getDescription(): string
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return '';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function up(Schema $schema): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // this up() migration is auto-generated, please modify it to your needs
 | 
				
			||||||
 | 
					        $this->addSql('ALTER TABLE user ADD url_id VARCHAR(13) NOT NULL');
 | 
				
			||||||
 | 
					        $this->addSql('ALTER TABLE wish ADD url_id VARCHAR(13) NOT NULL');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function down(Schema $schema): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // this down() migration is auto-generated, please modify it to your needs
 | 
				
			||||||
 | 
					        $this->addSql('ALTER TABLE `user` DROP url_id');
 | 
				
			||||||
 | 
					        $this->addSql('ALTER TABLE wish DROP url_id');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,7 @@ class RegistrationController extends AbstractController
 | 
				
			||||||
        $form->handleRequest($request);
 | 
					        $form->handleRequest($request);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($form->isSubmitted() && $form->isValid()) {
 | 
					        if ($form->isSubmitted() && $form->isValid()) {
 | 
				
			||||||
 | 
					            $user->setUrlId(uniqid());
 | 
				
			||||||
            // encode the plain password
 | 
					            // encode the plain password
 | 
				
			||||||
            $user->setPassword(
 | 
					            $user->setPassword(
 | 
				
			||||||
                $passwordEncoder->hashPassword(
 | 
					                $passwordEncoder->hashPassword(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ use Symfony\Component\Routing\Annotation\Route;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TradeController extends AbstractController
 | 
					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
 | 
					    public function sendEmail(MailerInterface $mailer, Offering $offer, OfferingRepository $offeringRepository, WishRepository $wishRepository): Response
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $user = $this->getUser();
 | 
					        $user = $this->getUser();
 | 
				
			||||||
| 
						 | 
					@ -35,7 +35,7 @@ class TradeController extends AbstractController
 | 
				
			||||||
                ->htmlTemplate('user/trade/offer_email.html.twig')
 | 
					                ->htmlTemplate('user/trade/offer_email.html.twig')
 | 
				
			||||||
                ->context([
 | 
					                ->context([
 | 
				
			||||||
                    'user' => $user,
 | 
					                    'user' => $user,
 | 
				
			||||||
                    'id' => $user->getId(),
 | 
					                    'urlId' => $user->getUrlId(),
 | 
				
			||||||
                ])
 | 
					                ])
 | 
				
			||||||
            ;
 | 
					            ;
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
| 
						 | 
					@ -49,6 +49,6 @@ class TradeController extends AbstractController
 | 
				
			||||||
            $this->addFlash('error','You can\'t trade with yourself!');
 | 
					            $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()]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
					    public function show_user(User $user, OfferingRepository $offeringRepository, WishRepository $wishRepository): Response
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->render('user/public.html.twig', [
 | 
					        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
 | 
					    public function deleteWish(Wish $wish): Response
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $user = $this->getUser();
 | 
					        $user = $this->getUser();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,6 +65,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private $zipCode;
 | 
					    private $zipCode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @ORM\Column(type="string", length=13)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private $urlId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct()
 | 
					    public function __construct()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->offerings = new ArrayCollection();
 | 
					        $this->offerings = new ArrayCollection();
 | 
				
			||||||
| 
						 | 
					@ -255,4 +260,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getUrlId(): ?string
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->urlId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function setUrlId(string $urlId): self
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->urlId = $urlId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,6 +27,11 @@ class Wish
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private $byUser;
 | 
					    private $byUser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * @ORM\Column(type="string", length=13)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private $urlId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getId(): ?int
 | 
					    public function getId(): ?int
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->id;
 | 
					        return $this->id;
 | 
				
			||||||
| 
						 | 
					@ -60,4 +65,16 @@ class Wish
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return (string) $this->getTitle();
 | 
					        return (string) $this->getTitle();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getUrlId(): ?string
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->urlId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function setUrlId(string $urlId): self
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->urlId = $urlId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,7 @@
 | 
				
			||||||
                            </div>
 | 
					                            </div>
 | 
				
			||||||
                        </a>
 | 
					                        </a>
 | 
				
			||||||
                        <div class="card-footer offer-footer">
 | 
					                        <div class="card-footer offer-footer">
 | 
				
			||||||
                            <a class="user-link" href="{{ path('user_public', { 'id': offer.byuser.id }) }}">
 | 
					                            <a class="user-link" href="{{ path('user_public', { 'urlId': offer.byuser.urlId }) }}">
 | 
				
			||||||
                                <p class="username"><i class="fas fa-user mt-3"></i> {{ offer.byUser }}</p>
 | 
					                                <p class="username"><i class="fas fa-user mt-3"></i> {{ offer.byUser }}</p>
 | 
				
			||||||
                            </a>
 | 
					                            </a>
 | 
				
			||||||
                            <p class="zip"><i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}</p>
 | 
					                            <p class="zip"><i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}</p>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -48,7 +48,7 @@
 | 
				
			||||||
                            </div>
 | 
					                            </div>
 | 
				
			||||||
                        </a>
 | 
					                        </a>
 | 
				
			||||||
                        <div class="card-footer offer-footer">
 | 
					                        <div class="card-footer offer-footer">
 | 
				
			||||||
                            <a class="user-link" href="{{ path('user_public', { 'id': offer.byuser.id }) }}">
 | 
					                            <a class="user-link" href="{{ path('user_public', { 'urlId': offer.byuser.id }) }}">
 | 
				
			||||||
                                <p class="username"><i class="fas fa-user mt-3"></i> {{ offer.byUser }}</p>
 | 
					                                <p class="username"><i class="fas fa-user mt-3"></i> {{ offer.byUser }}</p>
 | 
				
			||||||
                            </a>
 | 
					                            </a>
 | 
				
			||||||
                            <p class="zip"><i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}</p>
 | 
					                            <p class="zip"><i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}</p>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
<h1>{{ user.username }} wants to trade!</h1>
 | 
					<h1>{{ user.username }} wants to trade!</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<p>Checkout {{ user.username}}'s offers:</p>
 | 
					<p>Checkout {{ user.username}}'s offers:</p>
 | 
				
			||||||
<a href="{{ url('user_public', {'id': id}) }}">Link</a>
 | 
					<a href="{{ url('user_public', {'urlId': urlId}) }}">Link</a>
 | 
				
			||||||
<p>Reply to this email to start trading.</p>
 | 
					<p>Reply to this email to start trading.</p>
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@
 | 
				
			||||||
        {% for wish in wishes %}
 | 
					        {% for wish in wishes %}
 | 
				
			||||||
            <li class="list-group-item d-flex justify-content-between align-items-center"> {{ wish.title }}
 | 
					            <li class="list-group-item d-flex justify-content-between align-items-center"> {{ wish.title }}
 | 
				
			||||||
                <span>
 | 
					                <span>
 | 
				
			||||||
                    <a href="{{ path('delete_wish', {'id': wish.id}) }}" class="btn btn-danger" aria-label="Delete"><i class="fas fa-trash-alt" aria-hidden="true" title="Delete"></i></a>
 | 
					                    <a href="{{ path('delete_wish', {'urlId': wish.id}) }}" class="btn btn-danger" aria-label="Delete"><i class="fas fa-trash-alt" aria-hidden="true" title="Delete"></i></a>
 | 
				
			||||||
                </span>
 | 
					                </span>
 | 
				
			||||||
            </li>
 | 
					            </li>
 | 
				
			||||||
        {% endfor %}
 | 
					        {% endfor %}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue