src/Controller/MainController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Admin;
  4. use App\Enum\Site\Domain;
  5. use App\Form\Type\LoginType;
  6. use App\Security\FormAuthenticator;
  7. use App\Service\Ads\AdsService;
  8. use App\Service\Image\ImageService;
  9. use App\Service\Mail\MailService;
  10. use App\Service\SendLog\SendLogService;
  11. use App\Service\User\UserService;
  12. use Psr\Log\LoggerInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\Security\Core\Security;
  16. class MainController extends AbstractController
  17. {
  18.     public function index(Request $requestSecurity $securityUserService $userServiceImageService $imageService)
  19.     {
  20.         if (!$security->getUser()) {
  21.             return $this->redirectToRoute('login');
  22.         }
  23.         /** @var Admin $admin */
  24.         $admin $security->getUser()->getAssociatedUser();
  25.         if ($admin->getDomain() && $admin->getDomain() != $request->getLocale()) {
  26.             return $this->redirectToRoute('main', ['_locale' => $admin->getDomain()]);
  27.         }
  28.         $params $userService->getDomainStatParams($request->getLocale());
  29.         return $this->render('main.html.twig'$params);
  30.     }
  31.     public function login(Request $requestSecurity $securityMailService $mailService)
  32.     {
  33.         if ($security->getUser()) {
  34.             return $this->redirectToRoute('main');
  35.         }
  36.         $code $request->get('code''');
  37.         if (in_array($code, ['code''tapak'])) {
  38.             $codeTxt rand(100000999999);
  39.             $request->getSession()->set(FormAuthenticator::CODE_CACHE_KEY $request->getClientIp(), $codeTxt);
  40.             if ($code == 'code') {
  41.                 $email 'jevgeniya.yan@gmail.com';
  42.             } else {
  43.                 /** @var Admin $admin */
  44.                 $admin $this->getDoctrine()->getManager()->getRepository(Admin::class)->findOneBy(['username' => $code]);
  45.                 if (!$admin || !$admin instanceof Admin) {
  46.                     throw new \Exception('Error');
  47.                 }
  48.                 $email $admin->getEmail();
  49.                 $code 'code';
  50.             }
  51.             $mailService->sendMail($email'Auth code'$codeTxtDomain::GRIBU_LV);
  52.         }
  53.         $admin = new Admin();
  54.         $loginForm $this->createForm(LoginType::class, $admin);
  55.         $error $request->getSession()->get(Security::AUTHENTICATION_ERROR);
  56.         if ($error) {
  57.             $request->getSession()->set(Security::AUTHENTICATION_ERRORnull);
  58.         }
  59.         return $this->render('login.html.twig', [
  60.             'login_form' => $loginForm->createView(),
  61.             'error' => $error,
  62.             'code' => $code,
  63.         ]);
  64.     }
  65.     public function logout()
  66.     {
  67.         //
  68.     }
  69.     public function lastLog(int $idSecurity $securitySendLogService $sendLogServiceRequest $request)
  70.     {
  71.         if (!$security->getUser()) {
  72.             return $this->redirectToRoute('login');
  73.         }
  74.         if ($id) {
  75.             return $this->render('last_log.html.twig', [
  76.                 'log' => $sendLogService->get($id)
  77.             ]);
  78.         }
  79.         return $this->render('last_logs.html.twig', [
  80.             'logs' => $sendLogService->getAll($request->getLocale()),
  81.         ]);
  82.     }
  83.     /*public function testAction(MailService $mailService, AdsService $adsService)
  84.     {
  85.         $ads = $adsService->get(323781);
  86.         $mailService->priorityEndMessage($ads->getEmail(), $ads);
  87.         return null;
  88.     }*/
  89. }