src/Controller/LoginController.php line 119

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Env;
  4. use App\Func;
  5. use App\DTO\AppDTO;
  6. use App\Entity\User;
  7. use App\Service\Auth\Auth;
  8. use App\Service\Cart\Cart;
  9. use App\Service\Mail\Mail;
  10. use App\Repository\UserRepository;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Security\Core\Security;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\RequestStack;
  19. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  20. class LoginController extends AbstractASController
  21. {
  22.     private EntityManagerInterface $em;
  23.     protected AppDTO $app;
  24.     protected Auth $Auth;
  25.     //Repositories
  26.     private UserRepository $Users;
  27.     public function __construct(EntityManagerInterface $emAppDTO $appAuth $AuthSecurity $securityRequestStack $requestStack)
  28.     {
  29.         $this->requestStack $requestStack;
  30.         $this->em $em;
  31.         $this->app $app;
  32.         $this->Auth $Auth;
  33.         $this->Auth->setUser($security->getUser());
  34.         $this->Users $em->getRepository(User::class);
  35.     }
  36.     #[Route('/login'name'login_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  37.     #[Route('/{_locale}/login'name'login',  requirements: ['_locale' => '%app.langs%'])]    
  38.     public function login(AuthenticationUtils $authenticationUtilsRequest $requestCart $cartAuth $Auth): Response
  39.     {
  40.         // get the login error if there is one
  41.         $error $authenticationUtils->getLastAuthenticationError();
  42.         // last username entered by the user
  43.         $lastUsername $authenticationUtils->getLastUsername();
  44.         return $this->render('login/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  45.     }
  46.     
  47.     #[Route('/login/remind'name'login_remind_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  48.     #[Route('/{_locale}/login/remind'name'login_remind',  requirements: ['_locale' => '%app.langs%'])]
  49.     public function remind(Request $requestMail $Mail): Response
  50.     {
  51.         $submit $request->get('submit');
  52.         $email $request->get('email');
  53.         
  54.         if ($email) {
  55.             if(!$email) {
  56.                 $result = ['noerrors' => false"message" => $this->app->labels->get("field_cant_be_empty")];
  57.                 return new JsonResponse($result);
  58.             } else {
  59.                 $user $this->Users->findOneBy(['email' => $email]);
  60.                 if ($user) {
  61.                     $password $this->Auth->mkpass();
  62.                     $data = array(
  63.                         "pass" => $password,
  64.                     );
  65.                     $params = array(
  66.                         "email" => $user->getEmail(),
  67.                         "pass" => $password,
  68.                     );
  69.                     $user->setPassword($password);
  70.                     $this->em->flush();
  71.                     
  72.                     $Mail->send($this->app->sett->get('sitename'), Env::mail_from(), $email$this->app->labels->get("remind_message_theme"), Func::mess_from_tmp($this->app->templates->get("remind_message_template"), $params));
  73.                     $result = ['noerrors' => true"message" => $this->app->labels->get("password_sent")];
  74.                     return new JsonResponse($result);
  75.                 } else {
  76.                     $result = ['noerrors' => false"message" => $this->app->labels->get("email_not_found")];
  77.                     return new JsonResponse($result);
  78.                 }
  79.             }
  80.         } 
  81.           
  82.         return $this->render('login/remind.html.twig', [
  83.         ]);
  84.     }
  85.     #[Route('/logout'name'app_logout'defaults: ['_locale' => '%app.default_lang%'])]
  86.     #[Route('/{_locale}/logout'name'app_logout_locale',  requirements: ['_locale' => '%app.langs%'])]
  87.     public function logout(Security $security)
  88.     {
  89.         
  90.     }
  91.     #[Route(path'/connect/google'name'connect_google_start')]
  92.     public function connectGoogleAction(ClientRegistry $clientRegistry)
  93.     {
  94.         return $clientRegistry
  95.             ->getClient('google_main'// key used in config/packages/knpu_oauth2_client.yaml
  96.             ->redirect([], []);
  97.     }
  98.     #[Route(path'/connect/google/check'name'connect_google_check')]
  99.     public function connectGoogleCheckAction(Request $requestClientRegistry $clientRegistry)
  100.     {
  101.     }
  102.     #[Route(path'/connect/facebook'name'connect_facebook_start')]
  103.     public function connectFacebookAction(ClientRegistry $clientRegistry)
  104.     {
  105.         // on Symfony 3.3 or lower, $clientRegistry = $this->get('knpu.oauth2.registry');
  106.         // will redirect to Facebook!
  107.         return $clientRegistry
  108.             ->getClient('facebook_main'// key used in config/packages/knpu_oauth2_client.yaml
  109.             ->redirect([], []);
  110.     }
  111.     #[Route(path'/connect/facebook/check'name'connect_facebook_check')]
  112.     public function connectFacebookCheckAction(Request $requestClientRegistry $clientRegistry)
  113.     {        
  114.     }
  115. }