init project
This commit is contained in:
0
src/Controller/.gitignore
vendored
Normal file
0
src/Controller/.gitignore
vendored
Normal file
62
src/Controller/BackendAdmin/ActiverController.php
Normal file
62
src/Controller/BackendAdmin/ActiverController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\BackendAdmin;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use App\Entity\SoftwareActivation;
|
||||
|
||||
use App\Repository\SoftwareActivationRepository;
|
||||
|
||||
|
||||
#[Route('/admin/activer')]
|
||||
final class ActiverController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @param EntityManagerInterface $em
|
||||
* @param SoftwareActivationRepository $softwareActivationRepository
|
||||
*/
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private SoftwareActivationRepository $softwareActivationRepository
|
||||
)
|
||||
{
|
||||
$this->softwareActivationRepository = $softwareActivationRepository;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
#[Route('/index', name: 'admin_activer_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('backend/admin/activer/index.html.twig', [
|
||||
'softwareActivations'=>$this->softwareActivationRepository->findBy(['user'=>null], ["id"=>'DESC'])
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
#[Route('/activation/{id}', name: 'admin_activer_activation')]
|
||||
public function activation(SoftwareActivation $softwareActivation): Response
|
||||
{
|
||||
$softwareActivation->setStatu(1);
|
||||
$softwareActivation->setDateAdd(new \DateTime());
|
||||
$this->em->persist($softwareActivation);
|
||||
$this->em->flush();
|
||||
return $this->redirectToRoute('admin_activer_index');
|
||||
}
|
||||
|
||||
#[Route('/delete/{id}', name: 'admin_activer_delete')]
|
||||
public function delete(SoftwareActivation $softwareActivation): Response
|
||||
{
|
||||
$this->em->remove($softwareActivation);
|
||||
$this->em->flush();
|
||||
return $this->redirectToRoute('admin_activer_index');
|
||||
}
|
||||
}
|
||||
50
src/Controller/BackendAdmin/HomeController.php
Normal file
50
src/Controller/BackendAdmin/HomeController.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\BackendAdmin;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use App\Repository\GeolocationRepository;
|
||||
use App\Repository\SoftDownloaderRepository;
|
||||
|
||||
#[Route('/admin/home')]
|
||||
final class HomeController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @param UserRepository $userRepository
|
||||
* @param GeolocationRepository $geolocationRepository
|
||||
* @param SoftDownloaderRepository $softDownloaderRepository
|
||||
*/
|
||||
public function __construct(
|
||||
private UserRepository $userRepository,
|
||||
private GeolocationRepository $geolocationRepository,
|
||||
private SoftDownloaderRepository $softDownloaderRepository
|
||||
)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->geolocationRepository = $geolocationRepository;
|
||||
$this->softDownloaderRepository = $softDownloaderRepository;
|
||||
}
|
||||
|
||||
#[Route('/index', name: 'admin_home_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('backend/admin/home/index.html.twig', [
|
||||
"dateNow"=> (new \DateTime())->format('d/m/Y'),
|
||||
"nbrUsers"=> $this->userRepository->countUsersNow(),
|
||||
"nbrVisitors"=> $this->geolocationRepository->countGeolocationNow(),
|
||||
"geolocations"=> $this->geolocationRepository->getGeolocationsNow(),
|
||||
"nbrDownloaders"=> $this->softDownloaderRepository->getDownloadersNow()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
26
src/Controller/BackendAdmin/TestController.php
Normal file
26
src/Controller/BackendAdmin/TestController.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\BackendAdmin;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
|
||||
#[Route('/admin/test')]
|
||||
final class TestController extends AbstractController
|
||||
{
|
||||
|
||||
#[Route('/origin', name: 'admin_test_origin')]
|
||||
public function origin(): Response
|
||||
{
|
||||
return $this->render('backend/admin/test/origin_template.html.twig', []);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
93
src/Controller/BackendAdmin/UtilisateurController.php
Normal file
93
src/Controller/BackendAdmin/UtilisateurController.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\BackendAdmin;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\Partner;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use App\Repository\GeolocationRepository;
|
||||
|
||||
#[Route('/admin/utilisateur')]
|
||||
final class UtilisateurController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @param EntityManagerInterface $em
|
||||
* @param UserRepository $userRepository
|
||||
* @param GeolocationRepository $geolocationRepository
|
||||
*/
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private UserRepository $userRepository,
|
||||
private GeolocationRepository $geolocationRepository,
|
||||
)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->geolocationRepository = $geolocationRepository;
|
||||
}
|
||||
|
||||
#[Route('/index', name: 'admin_utilisateur_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('backend/admin/utilisateur/index.html.twig', [
|
||||
'users'=>$this->userRepository->findUsersWithoutAdminOrPartner()
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/change/role/partner/{id}', name: 'admin_utilisateur_change_role')]
|
||||
public function change_role_partner(User $user): Response
|
||||
{
|
||||
|
||||
|
||||
$user->addRole("ROLE_PARTNER");
|
||||
$partner = new Partner();
|
||||
$partner->setActive(true);
|
||||
$partner->setDateAdd(new \DateTime());
|
||||
$partner->setUser($user);
|
||||
$this->em->persist($partner);
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
|
||||
return $this->redirectToRoute('admin_utilisateur_index');
|
||||
}
|
||||
|
||||
|
||||
#[Route('/partner', name: 'admin_utilisateur_partner_index')]
|
||||
public function partner_index(): Response
|
||||
{
|
||||
return $this->render('backend/admin/utilisateur/partner.html.twig', [
|
||||
'partners'=>$this->userRepository->findByRoles(["ROLE_PARTNER"])
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/partner/delete/{id}', name: 'admin_utilisateur_partner_delete')]
|
||||
public function partner_delete(Partner $partner): Response
|
||||
{
|
||||
$user = $partner->getUser();
|
||||
$user->removeRole("ROLE_PARTNER");
|
||||
$this->em->persist($user);
|
||||
$this->em->remove($partner);
|
||||
$this->em->flush();
|
||||
return $this->render('backend/admin/utilisateur/partner.html.twig', [
|
||||
'partners'=>$this->userRepository->findByRoles(["ROLE_PARTNER"])
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/visitor', name: 'admin_utilisateur_visitor_index')]
|
||||
public function visitor_index(): Response
|
||||
{
|
||||
return $this->render('backend/admin/utilisateur/visitor.html.twig', [
|
||||
'geolocations'=>$this->geolocationRepository->findAll()
|
||||
]);
|
||||
}
|
||||
}
|
||||
61
src/Controller/BackendPartner/ActiverController.php
Normal file
61
src/Controller/BackendPartner/ActiverController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\BackendPartner;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use App\Entity\SoftwareActivation;
|
||||
|
||||
use App\Repository\SoftwareActivationRepository;
|
||||
|
||||
|
||||
#[Route('/partner/activer')]
|
||||
final class ActiverController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @param SoftwareActivationRepository $softwareActivationRepository
|
||||
*/
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private SoftwareActivationRepository $softwareActivationRepository
|
||||
)
|
||||
{
|
||||
$this->softwareActivationRepository = $softwareActivationRepository;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
#[Route('/index', name: 'partner_activer_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('backend/partner/activer.html.twig', [
|
||||
'softwareActivations'=>$this->softwareActivationRepository->findBy(['user'=>$this->getUser()], ["id"=>'DESC'])
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
#[Route('/activation/{id}', name: 'partner_activer_activation')]
|
||||
public function activation(SoftwareActivation $softwareActivation): Response
|
||||
{
|
||||
$softwareActivation->setStatu(1);
|
||||
$softwareActivation->setDateAdd(new \DateTime());
|
||||
$this->em->persist($softwareActivation);
|
||||
$this->em->flush();
|
||||
return $this->redirectToRoute('partner_activer_index');
|
||||
}
|
||||
|
||||
#[Route('/delete/{id}', name: 'partner_activer_delete')]
|
||||
public function delete(SoftwareActivation $softwareActivation): Response
|
||||
{
|
||||
$this->em->remove($softwareActivation);
|
||||
$this->em->flush();
|
||||
return $this->redirectToRoute('partner_activer_index');
|
||||
}
|
||||
}
|
||||
46
src/Controller/BackendPartner/HomeController.php
Normal file
46
src/Controller/BackendPartner/HomeController.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\BackendPartner;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use App\Repository\GeolocationRepository;
|
||||
use App\Repository\SoftDownloaderRepository;
|
||||
|
||||
#[Route('/partner/home')]
|
||||
final class HomeController extends AbstractController
|
||||
{
|
||||
|
||||
/**
|
||||
* @param UserRepository $userRepository
|
||||
* @param GeolocationRepository $geolocationRepository
|
||||
* @param SoftDownloaderRepository $softDownloaderRepository
|
||||
*/
|
||||
public function __construct(
|
||||
private UserRepository $userRepository,
|
||||
private GeolocationRepository $geolocationRepository,
|
||||
private SoftDownloaderRepository $softDownloaderRepository
|
||||
)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
$this->geolocationRepository = $geolocationRepository;
|
||||
$this->softDownloaderRepository = $softDownloaderRepository;
|
||||
}
|
||||
|
||||
#[Route('/downloader', name: 'partner_home_downloader')]
|
||||
public function downloader(): Response
|
||||
{
|
||||
return $this->render('backend/partner/downloader.html.twig', [
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
94
src/Controller/Frontend/DemoController.php
Normal file
94
src/Controller/Frontend/DemoController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Frontend;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Form\ParamDemoType;
|
||||
|
||||
use App\Entity\ParamDemo;
|
||||
use App\Entity\SoftDownloader;
|
||||
|
||||
use App\Repository\ParamDemoRepository;
|
||||
|
||||
|
||||
#[Route('/demo')]
|
||||
final class DemoController extends AbstractController
|
||||
{
|
||||
|
||||
/** @var EntityManagerInterface $em */
|
||||
private $em;
|
||||
|
||||
/** @var ParamDemoRepository $paramDemoRepository */
|
||||
private $paramDemoRepository;
|
||||
|
||||
/**
|
||||
* @param ParamDemoRepository $paramDemoRepository
|
||||
* @param EntityManagerInterface $em
|
||||
* @return $this
|
||||
*/
|
||||
public function __construct(
|
||||
ParamDemoRepository $paramDemoRepository,
|
||||
EntityManagerInterface $em
|
||||
){
|
||||
$this->paramDemoRepository = $paramDemoRepository;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
#[Route('/download', name: 'demo_download')]
|
||||
public function download(Request $request): Response
|
||||
{
|
||||
$paramDemo = $this->paramDemoRepository->findOneBy(['user'=>$this->getUser()]);
|
||||
if(!$paramDemo) $paramDemo = new ParamDemo();
|
||||
|
||||
$disabled = ($this->getUser()) ? false : true ;
|
||||
|
||||
$form = $this->createForm(ParamDemoType::class, $paramDemo, ['disabled'=> $disabled]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if($form->isSubmitted() && $form->isValid())
|
||||
{
|
||||
$paramDemo->setUser($this->getUser());
|
||||
$this->em->persist($paramDemo);
|
||||
$this->em->flush();
|
||||
|
||||
$this->addFlash('notice', "Modification a été modifié avec succès");
|
||||
}
|
||||
|
||||
return $this->render('frontend/demo/download.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'errors' => $form->getErrors()
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/parametre', name: 'demo_parametre')]
|
||||
public function parametre(Request $request): JsonResponse
|
||||
{
|
||||
$login = $request->get('login');
|
||||
|
||||
if(!$login) return new JsonResponse([]);
|
||||
|
||||
$paramDemo = $this->paramDemoRepository->findOneByLoginPassword($login);
|
||||
|
||||
return new JsonResponse($paramDemo->toArray());
|
||||
}
|
||||
|
||||
#[Route('/save_download', name: 'demo_save_download')]
|
||||
public function save_download(): Response
|
||||
{
|
||||
$softDownloader = new SoftDownloader();
|
||||
|
||||
$this->em->persist($softDownloader);
|
||||
$this->em->flush();
|
||||
|
||||
return new Response($softDownloader->getId());
|
||||
}
|
||||
}
|
||||
131
src/Controller/Frontend/HomeController.php
Normal file
131
src/Controller/Frontend/HomeController.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Frontend;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
|
||||
use App\Form\MailType;
|
||||
|
||||
use App\Repository\GeolocationRepository;
|
||||
|
||||
use ReCaptcha\ReCaptcha;
|
||||
|
||||
final class HomeController extends AbstractController
|
||||
{
|
||||
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @param GeolocationRepository $geolocationRepository
|
||||
* @param RequestStack $requestStack
|
||||
*/
|
||||
public function __construct(private GeolocationRepository $geolocationRepository,
|
||||
RequestStack $requestStack)
|
||||
{
|
||||
|
||||
$this->geolocationRepository = $geolocationRepository;
|
||||
$this->session = $requestStack->getSession();
|
||||
}
|
||||
|
||||
#[Route('/', name: 'home_index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('frontend/home/index.html.twig', [
|
||||
"form"=> $this->createForm(MailType::class),
|
||||
"geoVisitor" => $this->session->get('geoVisitor'),
|
||||
'GOOGLE_RECAPTCHA_SITE_KEY' => $_ENV['GOOGLE_RECAPTCHA_SITE_KEY'],
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
#[Route('/gallery', name: 'home_gallery')]
|
||||
public function gallery(ParameterBagInterface $params): Response
|
||||
{
|
||||
$directory = $params->get('app.images.screenshot');
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->files()->in($directory);
|
||||
|
||||
$fileList = [];
|
||||
foreach ($finder as $file) {
|
||||
$fileList[] = $file->getRelativePathname();
|
||||
}
|
||||
|
||||
sort($fileList);
|
||||
|
||||
return $this->render('frontend/home/gallery.html.twig', [
|
||||
'files'=>$fileList
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/geolocation', name: 'home_geolocation')]
|
||||
public function geolocation(Request $request): Response
|
||||
{
|
||||
$arrResultApi = json_decode($request->get('api'), true);
|
||||
if($arrResultApi)
|
||||
{
|
||||
$this->geolocationRepository->setGeolocation($arrResultApi);
|
||||
$this->session->set('geoVisitor', true);
|
||||
}
|
||||
return new Response('true');
|
||||
}
|
||||
|
||||
|
||||
#[Route('/contact', name: 'home_contact')]
|
||||
public function contact(MailerInterface $mailer, Request $request): Response
|
||||
{
|
||||
$form = $this->createForm(MailType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if($form->isSubmitted() && $form->isValid())
|
||||
{
|
||||
$recaptcha = new ReCaptcha($_ENV['GOOGLE_RECAPTCHA_SECRET']);
|
||||
|
||||
$token = $form->get('recaptcha')->getData();
|
||||
|
||||
$response = $recaptcha->setExpectedAction('submit')
|
||||
->setScoreThreshold(0.5)
|
||||
->verify($token, $request->getClientIp());
|
||||
|
||||
if ($response->isSuccess())
|
||||
{
|
||||
$fullname = $form->get('fullname')->getData();
|
||||
$from = $form->get('email')->getData();
|
||||
$subject = $form->get('subject')->getData();
|
||||
$message = $form->get('message')->getData();
|
||||
|
||||
$email = (new Email())
|
||||
->from($from)
|
||||
->to('contact@powerpme.com')
|
||||
->subject($fullname." ".$subject)
|
||||
->text($message);
|
||||
|
||||
try {
|
||||
$mailer->send($email);
|
||||
$this->addFlash('notice-email', "mail a été envoyé avec succès");
|
||||
} catch (TransportExceptionInterface $e) {
|
||||
$this->addFlash('erreur-email', $e->getMessage());
|
||||
}
|
||||
}else{
|
||||
|
||||
$this->addFlash('erreur-email', 'ReCaptcha invalide');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirect("/#contact");
|
||||
}
|
||||
}
|
||||
81
src/Controller/Frontend/SecurityController.php
Normal file
81
src/Controller/Frontend/SecurityController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Frontend;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
||||
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
|
||||
|
||||
use App\Security\LoginAuthenticator;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
use App\Form\UserRegistrationType;
|
||||
|
||||
final class SecurityController extends AbstractController
|
||||
{
|
||||
#[Route(path: '/login', name: 'security_login')]
|
||||
public function login(AuthenticationUtils $authenticationUtils): Response
|
||||
{
|
||||
if ($this->getUser()) {
|
||||
return $this->redirectToRoute('home_index');
|
||||
}
|
||||
|
||||
// get the login error if there is one
|
||||
$error = $authenticationUtils->getLastAuthenticationError();
|
||||
|
||||
// last username entered by the user
|
||||
$lastUsername = $authenticationUtils->getLastUsername();
|
||||
|
||||
return $this->render('frontend/security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error, 'titlePage' => 'Connexion']);
|
||||
}
|
||||
|
||||
#[Route(path: '/logout', name: 'security_logout')]
|
||||
public function logout(Security $security): RedirectResponse
|
||||
{
|
||||
$response = $security->logout(false);
|
||||
|
||||
return $this->redirectToRoute('homepage');
|
||||
}
|
||||
|
||||
#[Route(path: '/registration', name: 'security_registration')]
|
||||
public function registration(Request $request,
|
||||
UserPasswordHasherInterface $userPasswordHasher,
|
||||
UserAuthenticatorInterface $userAuthenticator,
|
||||
LoginAuthenticator $authenticator,
|
||||
EntityManagerInterface $em): Response
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$form = $this->createForm(UserRegistrationType::class, $user);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if($form->isSubmitted() && $form->isValid())
|
||||
{
|
||||
$user->setPassword($userPasswordHasher->hashPassword($user, $form->get('password')->getData()));
|
||||
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
return $userAuthenticator->authenticateUser($user, $authenticator, $request);
|
||||
}
|
||||
|
||||
return $this->render('frontend/security/register.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'errors' => $form->getErrors(),
|
||||
'titlePage' => 'Inscription',
|
||||
]);
|
||||
}
|
||||
}
|
||||
112
src/Controller/Frontend/SoftwareController.php
Normal file
112
src/Controller/Frontend/SoftwareController.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Frontend;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Service\CryptoService;
|
||||
|
||||
use App\Repository\UserRepository;
|
||||
use App\Repository\SoftwareActivationRepository;
|
||||
|
||||
|
||||
#[Route('/software')]
|
||||
final class SoftwareController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @param SoftwareActivationRepository $softwareActivationRepository
|
||||
* @param UserRepository $userRepository
|
||||
* @param EntityManagerInterface $em
|
||||
* @return $this
|
||||
*/
|
||||
public function __construct(
|
||||
private UserRepository $userRepository,
|
||||
private SoftwareActivationRepository $softwareActivationRepository,
|
||||
private CryptoService $cryptoService,
|
||||
private EntityManagerInterface $em
|
||||
){
|
||||
$this->em = $em;
|
||||
$this->userRepository = $userRepository;
|
||||
$this->cryptoService = $cryptoService;
|
||||
$this->softwareActivationRepository = $softwareActivationRepository;
|
||||
}
|
||||
|
||||
#[Route('/activation', name: 'software_activation')]
|
||||
public function activation(Request $request): JsonResponse
|
||||
{
|
||||
$id = $request->get('id');
|
||||
$companyName = $request->get('CompanyName');
|
||||
$companyMF = $request->get('CompanyMF');
|
||||
$pcName = $request->get('PCName');
|
||||
$partnerEmail = $request->get('Partner');
|
||||
$disqueNom = $request->get('DisqueNom');
|
||||
$disqueModel = $request->get('DisqueModel');
|
||||
$disqueSerial = $request->get('DisqueSerial');
|
||||
$user = null;
|
||||
$statu = 0;
|
||||
|
||||
/*
|
||||
pour le code
|
||||
0 | null --> n'ai pas encore activer
|
||||
1 --> activer
|
||||
2 --> La demande a été bien envoyer pour activé le logiciel
|
||||
n --> erreur
|
||||
*/
|
||||
if($id){
|
||||
$softwareActivation = $this->softwareActivationRepository->find($id);
|
||||
}else{
|
||||
$softwareActivation = $this->softwareActivationRepository->findOneBy(['disqueNom'=>$disqueNom, 'disqueModel'=>$disqueModel, 'disqueSerial'=>$disqueSerial]);
|
||||
}
|
||||
|
||||
|
||||
if($partnerEmail)
|
||||
{
|
||||
$user = $this->userRepository->findOneBy(['email'=>$partnerEmail]);
|
||||
if(!$user){
|
||||
return new JsonResponse(['code'=>404, 'message'=>'partenaire inconnu', 'body'=>[]]);
|
||||
}else{
|
||||
$partner = $user->getPartner();
|
||||
if($partner){
|
||||
if(!$partner->isActive()){
|
||||
return new JsonResponse(['code'=>403, 'message'=>'Accès refusé au partner', 'body'=>[]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($softwareActivation)
|
||||
{
|
||||
if($softwareActivation->getStatu() == 1)
|
||||
{
|
||||
return new JsonResponse(['code'=>1, 'message'=>'true', 'body'=>[
|
||||
'Id'=>$softwareActivation->getId(),
|
||||
'Date'=>$softwareActivation->getDateAddFormat('Y-m-d H:i:s'),
|
||||
'DisqueNom'=>$this->cryptoService->chiffrer($disqueNom),
|
||||
'DisqueModel'=>$this->cryptoService->chiffrer($disqueModel),
|
||||
'DisqueSerial'=>$this->cryptoService->chiffrer($disqueSerial),
|
||||
]]);
|
||||
}else{
|
||||
return new JsonResponse(['code'=>0, 'message'=>"n'ai pas encore activer", 'body'=>[
|
||||
'Id'=>$softwareActivation->getId(),
|
||||
]]);
|
||||
}
|
||||
|
||||
}else{
|
||||
$softwareActivation = $this->softwareActivationRepository->addSoftwareActivation($companyName, $companyMF, $pcName, $user, $disqueNom, $disqueModel, $disqueSerial, $statu);
|
||||
return new JsonResponse(['code'=>2, 'message'=>'La demande a été bien envoyer pour activé le logiciel', 'body'=>[
|
||||
'Id'=>$softwareActivation->getId(),
|
||||
]]);
|
||||
}
|
||||
|
||||
return new JsonResponse(['code'=>500, 'message'=>"erreur lors d'activation du logiciel", 'body'=>[]]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user