Skip to content

Commit

Permalink
#35: ajout de l'envoie de mail à la validation d'un compte
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste-its committed Mar 1, 2021
1 parent 940cf14 commit 8a99dbd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 18 deletions.
56 changes: 38 additions & 18 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Controller;

use App\Entity\Customer;
use App\Entity\HalfDayAdjustment;
use App\Form\EditCustomerType;
use App\Form\HalfDayAdjustmentType;
Expand All @@ -11,21 +12,25 @@
use App\Repository\SubscriptionRepository;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Swift_Mailer;
use Swift_Message;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Form\HalfDayType;
use App\Form\MonthType;
use App\Form\PlaceType;
use App\Form\PromoType;
use App\Form\CustomerSettingStatusType;
use App\Form\TextHomeType;
use App\Repository\CustomerRepository;
use App\Repository\PromoRepository;

class AdminController extends AbstractController
{

private $adminMail = "[email protected]";
private $checkInRepository;
private $customerRepository;
private $subscriptionRepository;
Expand Down Expand Up @@ -105,29 +110,44 @@ public function activation()
}

/**
* @param $id
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @param Customer $customer
* @param Swift_Mailer $mailer
* @return RedirectResponse
* @Route("/admin/activate/{id}", name="admin_activate")
*/
public function activate($id)
public function activate(Customer $customer, Swift_Mailer $mailer): Response
{
$customer = $this->subscriptionRepository->findOneBy(
$subscription = $this->subscriptionRepository->findOneBy(
[
'customer' => $id
'customer' => $customer->getId()
]
);
$promo = $this->promoRepository->findOneBy(
[
'customer' => $id
'customer' => $customer->getId()
]
);
if ($customer->getActive() == 0) {
$customer->setActive(1);
if ($subscription->getActive() == 0) {
$subscription->setActive(1);
$promo->setCounter($promo->getCounter() + 0);

$message = (new Swift_Message('Modification de votre mot de passe'))
->setFrom($this->adminMail)
->setTo($customer->getMail())
->setBody(
$this->renderView(
'admin/mail-activation.html.twig',
[
'name' => $customer->getFirstname(),
]
),
'text/html'
);
$mailer->send($message);
} else {
$customer->setActive(0);
$subscription->setActive(0);
}
$this->manager->persist($customer);
$this->manager->persist($subscription);
$this->manager->persist($promo);
$this->manager->flush();

Expand All @@ -136,7 +156,7 @@ public function activate($id)

/**
* @param $id
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
* @Route("/admin/profile/{id}", name="admin_profile")
*/
public function profile($id, Request $request)
Expand All @@ -150,7 +170,7 @@ public function profile($id, Request $request)
if ($counter->isSubmitted() && $counter->isValid()) {
$this->manager->persist($promo);
$this->manager->flush();
};
}

$customerForm = $this->createForm(EditCustomerType::class, $customer);
$customerForm->handleRequest($request);
Expand Down Expand Up @@ -208,7 +228,7 @@ public function boom()

/**
* @param $id
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
* @Route("/admin/switchrole/{id}", name="admin_switchrole")
*/
public function switch($id)
Expand All @@ -227,7 +247,7 @@ public function switch($id)

/**
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @return Response
* @Route("/admin/text", name="admin_text")
*/
public function text(Request $request)
Expand Down Expand Up @@ -319,10 +339,10 @@ public function text(Request $request)
}

/**
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @return RedirectResponse
* @Route("/admin/textactive", name="admin_textactive")
*/
public function textActive()
public function textActive(): Response
{
$option = $this->optionsRepository->findOneBy(
[
Expand Down Expand Up @@ -553,7 +573,7 @@ public function price(OptionsRepository $optionsRepository, Request $request)
['customer_id' => $customer->getId(), 'arrival_month' => $data],
['id' => 'DESC']
);
};
}

return $this->render(
'admin/facturation.html.twig',
Expand Down
31 changes: 31 additions & 0 deletions templates/admin/mail-activation.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
<body>
<table style="font-family: sans-serif">
<tr>
<th><img src="http://www.laplagedigitale.eu/wp-content/themes/slate/images/flex/flex-08.png" height="50px" alt=""></th>
</tr>
<tr></tr>
<tr>
<td>Bonjour, {{ name }}</td>
</tr>
<tr>
<td>Votre compte a été validé !</td>
</tr>
<tr>
<td>Vous pouvez désormais profiter de <strong><a href="{{app.request.getSchemeAndHttpHost()}}">notre espace</a></strong> de coworking.</td>
</tr>
<tr></tr>
<tr>
<td>A bientôt dans l'espace flex !</td>
</tr>
<tr>
<th><img src="http://www.laplagedigitale.eu/wp-content/uploads/2015/04/plage-digitale.jpg" height="50px" alt=""></th>
</tr>
</table>
</body>
</html>

0 comments on commit 8a99dbd

Please sign in to comment.