-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#35: ajout de l'envoie de mail à la validation d'un compte
- Loading branch information
1 parent
940cf14
commit 8a99dbd
Showing
2 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Customer; | ||
use App\Entity\HalfDayAdjustment; | ||
use App\Form\EditCustomerType; | ||
use App\Form\HalfDayAdjustmentType; | ||
|
@@ -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; | ||
|
@@ -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(); | ||
|
||
|
@@ -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) | ||
|
@@ -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); | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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( | ||
[ | ||
|
@@ -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', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |