Skip to content

Commit

Permalink
fix(mailer): update mailer dsn and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-brtrd committed Jul 25, 2023
1 parent 61819da commit 7c78d23
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 73 deletions.
3 changes: 2 additions & 1 deletion .env.prod
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
DATABASE_URL=mysql://wgbt7219_pierre:[email protected]/wgbt7219_cours_sf6?serverVersion=8.0.25&charset=utf8
DATABASE_URL=mysql://wgbt7219_pierre:[email protected]/wgbt7219_cours_sf6?serverVersion=8.0.25&charset=utf8
MAILER_DSN="smtp://contact%40pierre-bertrand-webmarketing.com:19970506Mai%[email protected]:465"
3 changes: 2 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
PANTHER_ERROR_SCREENSHOT_DIR=%kernel.cache_dir%/error-screenshots
DATABASE_URL=sqlite:///%kernel.cache_dir%/test.db
PANTHER_APP_ENV=test
MAILER_DSN="smtp://contact%40pierre-bertrand-webmarketing.com:19970506Mai%[email protected]:465"

# Juste pour le débug (une fenêtre va réellement s'ouvrir,
# à utiliser SEULEMENT pendant la mise en place des tests)
Expand Down
50 changes: 25 additions & 25 deletions config/packages/liip_imagine.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# Documentation on how to configure the bundle can be found at: https://symfony.com/doc/current/bundles/LiipImagineBundle/basic-usage.html
liip_imagine:
# driver: "gd"
resolvers:
default:
web_path:
web_root: "%kernel.project_dir%/public"
cache_prefix: "media/cache/resolve"
# driver: "gd"
twig:
mode: lazy
resolvers:
default:
web_path:
web_root: "%kernel.project_dir%/public"
cache_prefix: "media/cache/resolve"

loaders:
article_image:
filesystem:
data_root: "%kernel.project_dir%/public"
loaders:
article_image:
filesystem:
data_root: "%kernel.project_dir%/public"

filter_sets:
cache: ~
# the name of the "filter set"
thumb_list:
data_loader: article_image
quality: 75
filters:
thumbnail:
{ size: [231, 154], position: center, mode: outbound }
filter_sets:
cache: ~
# the name of the "filter set"
thumb_list:
data_loader: article_image
quality: 75
filters:
thumbnail: { size: [231, 154], position: center, mode: outbound }

banner_article:
data_loader: article_image
quality: 100
filters:
thumbnail:
{ size: [1440, 570], position: center, mode: outbound }
banner_article:
data_loader: article_image
quality: 100
filters:
thumbnail: { size: [1440, 570], position: center, mode: outbound }
Binary file modified drivers/chromedriver
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Controller/Security/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Controller\Security;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Controller/Security/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
namespace App\Controller\Security;

use App\Entity\User;
use App\Security\EmailVerifier;
use App\Form\RegistrationFormType;
use App\Repository\UserRepository;
use Symfony\Component\Mime\Address;
use App\Security\EmailVerifier;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mime\Address;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;

class RegistrationController extends AbstractController
Expand All @@ -26,7 +26,7 @@ public function __construct(EmailVerifier $emailVerifier)
$this->emailVerifier = $emailVerifier;
}

#[Route('/register', name: 'register')]
#[Route('/register', name: 'register', methods: ['GET', 'POST'])]
public function register(Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response
{
$user = new User();
Expand Down Expand Up @@ -66,7 +66,7 @@ public function register(Request $request, UserPasswordHasherInterface $userPass
]);
}

#[Route('/verify/email', name: 'app.verify.email')]
#[Route('/verify/email', name: 'app.verify.email', methods: ['GET'])]
public function verifyUserEmail(Request $request, TranslatorInterface $translator, UserRepository $userRepository): Response
{
$id = $request->query->get('id');
Expand Down
1 change: 0 additions & 1 deletion src/DataFixtures/Providers/ArticleImageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function uploadImageArticle(): ArticleImage

public function uploadImageUser(string $file = 'default.png'): UploadedFile
{
/** @var array<string> $files */
$file = realpath(\dirname(__DIR__).'/Images/'.$file);

$imageFile = new File($file);
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ public function getUser(): User|UserInterface|null
}

/**
* @param User|UserInterface|null $user
* @param ?User $user
*
* @return $this
*/
public function setUser(User|UserInterface|null $user): static
public function setUser(?User $user): static
{
$this->user = $user;

Expand Down
10 changes: 6 additions & 4 deletions src/EventListener/ArticleImageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\EventListener;

use App\Entity\Article;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
use Doctrine\ORM\Events;
use Symfony\Component\HttpKernel\KernelInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;

#[AsEntityListener(event: Events::postRemove, method: 'postRemove', entity: Article::class)]
class ArticleImageListener
Expand All @@ -18,13 +18,15 @@ public function __construct(
public function postRemove(Article $article): void
{
$dir = $this->kernel->getProjectDir()
. '/public/images/articles/'
. $article->getSlug();
.'/public/images/articles/'
.$article->getSlug();

$files = glob("$dir/*");

foreach ($files as $file) {
if (is_file($file)) unlink($file);
if (is_file($file)) {
unlink($file);
}
}

if (is_dir($dir)) {
Expand Down
32 changes: 16 additions & 16 deletions src/Form/RegistrationFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Vich\UploaderBundle\Form\Type\VichImageType;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;
use Vich\UploaderBundle\Form\Type\VichImageType;

class RegistrationFormType extends AbstractType
{
Expand All @@ -23,7 +23,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('email', EmailType::class, [
'label' => 'form.user.fields.email.label',
'attr' => [
'placeholder' => 'form.user.fields.email.placeholder'
'placeholder' => 'form.user.fields.email.placeholder',
],
'required' => true,
])
Expand All @@ -32,7 +32,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'first_options' => [
'attr' => [
'autocomplete' => 'new-password',
'placeholder' => 'form.user.fields.password.placeholder'
'placeholder' => 'form.user.fields.password.placeholder',
],
'constraints' => [
new NotBlank([
Expand All @@ -47,15 +47,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
new Regex(
pattern: '/^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,16}$/',
message: 'form.user.password.regex',
)
),
],
'label' => 'form.user.fields.password.main',
],
'second_options' => [
'label' => 'form.user.fields.password.repeat',
'attr' => [
'placeholder' => 'form.user.fields.password.placeholder',
]
],
],
'invalid_message' => 'form.user.validator.password.no_match',
// Instead of being set onto the object directly,
Expand All @@ -65,35 +65,35 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('prenom', TextType::class, [
'label' => 'form.user.fields.firstname.label',
'attr' => [
'placeholder' => 'form.user.fields.firstname.placeholder'
'placeholder' => 'form.user.fields.firstname.placeholder',
],
'required' => true,
])
->add('nom', TextType::class, [
'label' => 'form.user.fields.lastname.label',
'attr' => [
'placeholder' => 'form.user.fields.lastname.placeholder'
'placeholder' => 'form.user.fields.lastname.placeholder',
],
'required' => true,
])
->add('address', TextType::class, [
'label' => 'form.user.fields.address.label',
'attr' => [
'placeholder' => 'form.user.fields.address.placeholder'
'placeholder' => 'form.user.fields.address.placeholder',
],
'required' => true,
])
->add('zipCode', TextType::class, [
'label' => 'form.user.fields.zipcode.label',
'attr' => [
'placeholder' => 'form.user.fields.zipcode.placeholder'
'placeholder' => 'form.user.fields.zipcode.placeholder',
],
'required' => true,
])
->add('ville', TextType::class, [
'label' => 'form.user.fields.city.label',
'attr' => [
'placeholder' => 'form.user.fields.city.placeholder'
'placeholder' => 'form.user.fields.city.placeholder',
],
'required' => true,
])
Expand Down
12 changes: 12 additions & 0 deletions src/Security/EmailVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Security;

use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -19,6 +20,15 @@ public function __construct(
) {
}

/**
* Send email confirmation.
*
* @param string $verifyEmailRouteName
* @param User $user
* @param TemplatedEmail $email
*
* @return void
*/
public function sendEmailConfirmation(string $verifyEmailRouteName, UserInterface $user, TemplatedEmail $email): void
{
$signatureComponents = $this->verifyEmailHelper->generateSignature(
Expand All @@ -39,6 +49,8 @@ public function sendEmailConfirmation(string $verifyEmailRouteName, UserInterfac
}

/**
* @param User $user
*
* @throws VerifyEmailExceptionInterface
*/
public function handleEmailConfirmation(Request $request, UserInterface $user): void
Expand Down
4 changes: 2 additions & 2 deletions src/Security/UserChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Security;

use App\Entity\User;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Core\User\UserInterface;

class UserChecker implements UserCheckerInterface
{
Expand Down
1 change: 0 additions & 1 deletion src/Services/ArticleDirectoryNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Entity\ArticleImage;
use Vich\UploaderBundle\Mapping\PropertyMapping;
use Symfony\Component\HttpKernel\KernelInterface;
use Vich\UploaderBundle\Naming\DirectoryNamerInterface;

class ArticleDirectoryNamer implements DirectoryNamerInterface
Expand Down
20 changes: 10 additions & 10 deletions tests/Controller/SecurityControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public function testRegisterNewUser()
'registration_form[prenom]' => 'John',
'registration_form[nom]' => 'Doe',
'registration_form[email]' => '[email protected]',
'registration_form[password][first]' => 'Test1234',
'registration_form[password][second]' => 'Test1234',
'registration_form[plainPassword][first]' => 'Test1234!',
'registration_form[plainPassword][second]' => 'Test1234!',
'registration_form[address]' => 'XX rue de test',
'registration_form[zipCode]' => '75000',
'registration_form[ville]' => 'Paris',
Expand All @@ -145,8 +145,8 @@ public function testRegisterNewUserWithInvalidEmail()
'registration_form[prenom]' => 'John',
'registration_form[nom]' => 'Doe',
'registration_form[email]' => 'john@com',
'registration_form[password][first]' => 'Test1234',
'registration_form[password][second]' => 'Test1234',
'registration_form[plainPassword][first]' => 'Test1234!',
'registration_form[plainPassword][second]' => 'Test1234!',
'registration_form[address]' => 'XX rue de test',
'registration_form[zipCode]' => '75000',
'registration_form[ville]' => 'Paris',
Expand All @@ -163,8 +163,8 @@ public function testRegisterNewUserWithInvalidZipCode()
'registration_form[prenom]' => 'John',
'registration_form[nom]' => 'Doe',
'registration_form[email]' => '[email protected]',
'registration_form[password][first]' => 'Test1234',
'registration_form[password][second]' => 'Test1234',
'registration_form[plainPassword][first]' => 'Test1234!',
'registration_form[plainPassword][second]' => 'Test1234!',
'registration_form[address]' => 'XX rue de test',
'registration_form[zipCode]' => 'ldjfsldkjf',
'registration_form[ville]' => 'Paris',
Expand All @@ -181,8 +181,8 @@ public function testRegisterNewUserWithInvalidPassword()
'registration_form[prenom]' => 'John',
'registration_form[nom]' => 'Doe',
'registration_form[email]' => '[email protected]',
'registration_form[password][first]' => 'test',
'registration_form[password][second]' => 'test',
'registration_form[plainPassword][first]' => 'test',
'registration_form[plainPassword][second]' => 'test',
'registration_form[address]' => 'XX rue de test',
'registration_form[zipCode]' => '75000',
'registration_form[ville]' => 'Paris',
Expand All @@ -199,8 +199,8 @@ public function testRegisterNewUserWithInvalidSecondPassword()
'registration_form[prenom]' => 'John',
'registration_form[nom]' => 'Doe',
'registration_form[email]' => '[email protected]',
'registration_form[password][first]' => 'Test1234',
'registration_form[password][second]' => 'test',
'registration_form[plainPassword][first]' => 'Test1234!',
'registration_form[plainPassword][second]' => 'test',
'registration_form[address]' => 'XX rue de test',
'registration_form[zipCode]' => '75000',
'registration_form[ville]' => 'Paris',
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/UserTestFixtures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ App\Entity\User:
address: "15 rue de paradis"
zipCode: "73250"
ville: "Chambéry"
isVerified: true

userEditor:
email: [email protected]
Expand Down
Loading

0 comments on commit 7c78d23

Please sign in to comment.