|
17 | 17 | use AppBundle\Association\Model\CompanyMemberInvitation;
|
18 | 18 | use AppBundle\Association\Model\Repository\CompanyMemberInvitationRepository;
|
19 | 19 | use AppBundle\Association\Model\Repository\CompanyMemberRepository;
|
| 20 | +use AppBundle\Association\Model\Repository\TechletterSubscriptionsRepository; |
| 21 | +use AppBundle\Association\Model\Repository\TechletterUnsubscriptionsRepository; |
20 | 22 | use AppBundle\Association\Model\Repository\UserRepository;
|
21 | 23 | use AppBundle\Association\Model\User;
|
22 | 24 | use AppBundle\LegacyModelFactory;
|
@@ -565,4 +567,45 @@ private function prepareGeneralMeetingsReportsList()
|
565 | 567 |
|
566 | 568 | return $reports;
|
567 | 569 | }
|
| 570 | + |
| 571 | + public function techletterAction() |
| 572 | + { |
| 573 | + return $this->render(':site/member:techletter.html.twig', [ |
| 574 | + 'subscribed' => $this->get('ting')->get(TechletterSubscriptionsRepository::class)->hasUserSubscribed($this->getUser()), |
| 575 | + 'feeUpToDate' => ($this->getUser() !== null and $this->getUser()->getLastSubscription() > new \DateTime()), |
| 576 | + 'token' => $this->get('security.csrf.token_manager')->getToken('techletter_subscription'), |
| 577 | + ]); |
| 578 | + } |
| 579 | + |
| 580 | + public function techletterSubscribeAction(Request $request) |
| 581 | + { |
| 582 | + $user = $this->getUser(); |
| 583 | + $token = $this->get('security.csrf.token_manager')->getToken('techletter_subscription'); |
| 584 | + |
| 585 | + if ( |
| 586 | + $user === null |
| 587 | + || $user->getLastSubscription() < new \DateTime() |
| 588 | + || $request->request->has('_csrf_token') === false |
| 589 | + || $request->request->get('_csrf_token') !== $token->getValue() |
| 590 | + ) { |
| 591 | + throw $this->createAccessDeniedException('You cannot subscribe to the techletter'); |
| 592 | + } |
| 593 | + |
| 594 | + $this->addFlash('success', "Vous êtes maintenant inscrit à la veille de l'AFUP"); |
| 595 | + |
| 596 | + $this->get('ting')->get(TechletterSubscriptionsRepository::class)->subscribe($user); |
| 597 | + |
| 598 | + return $this->redirectToRoute('member_techletter'); |
| 599 | + } |
| 600 | + |
| 601 | + public function techletterUnsubscribeAction(Request $request) |
| 602 | + { |
| 603 | + $techletterUnsubscriptionRepository = $this->get('ting')->get(TechletterUnsubscriptionsRepository::class); |
| 604 | + $techletterUnsubscription = $techletterUnsubscriptionRepository->createFromUser($this->getUser()); |
| 605 | + $techletterUnsubscriptionRepository->save($techletterUnsubscription); |
| 606 | + |
| 607 | + $this->addFlash('success', "Vous êtes maintenant désincrit à la veille de l'AFUP"); |
| 608 | + |
| 609 | + return $this->redirectToRoute('member_techletter'); |
| 610 | + } |
568 | 611 | }
|
0 commit comments