src/Controller/AuthController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\ApiService;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. /**
  8.  * Class AuthController
  9.  * @package App\Controller
  10.  *@Route("/auth")
  11.  */
  12. class AuthController extends  AbstractController
  13. {
  14.     /**
  15.      * @var ApiService
  16.      */
  17.     private $apiService;
  18.     public function __construct(ApiService $apiService)
  19.     {
  20.         $this->apiService $apiService;
  21.     }
  22.     /**
  23.      * @Route("/login",name="app_login",methods={"POST","GET"})
  24.      */
  25.     public  function  loginAction(){
  26.         return $this->render("auth/login.html.twig");
  27.     }
  28.     /**
  29.      * @Route("/reset-password",name="app_reset_password",methods={"GET"})
  30.      */
  31.     public  function  ResetPasswordAction(){
  32.         return $this->render("auth/reset_password.html.twig");
  33.     }
  34.     /**
  35.      * @Route("/updated-password",name="app_updated_password",methods={"GET"})
  36.      */
  37.     public  function  UpdatedPasswordAction(Request $request){
  38.        $error null;
  39.        $email null ;
  40.         try{
  41.             $token $request->query->get("token");
  42.             if (empty($token))
  43.                 $error "token invalide";
  44.              if (!$error) {
  45.                  $response $this->apiService->verifyToken($token);
  46.                  $email $response["response"] ? $response["response"]["email"] : null ;
  47.                  if ($response["error"])
  48.                      $error =$response["error"];
  49.              }
  50.         }catch (\Exception $exception){
  51.           $error $exception->getMessage();
  52.         }
  53.         $template = !$error "auth/updated_password.html.twig":"error/error500.html.twig";
  54.         return $this->render($template,["error"=>$error,"email"=>$email]);
  55.     }
  56.     /**
  57.      * @Route("/registration",name="app_registration",methods={"POST","GET"})
  58.      */
  59.     public  function  RegistrationAction(){
  60.         return $this->render("auth/registration.html.twig");
  61.     }
  62.     /**
  63.      * @Route("/activated",name="app_activation_compte",methods={"GET"})
  64.      */
  65.     public  function  activatedAction(Request $request){
  66.         $token $request->query->get("token");
  67.        $response =  $this->apiService->activatedUser($token);
  68.         $message $response["success"] ? "Votre compte a été activé avce success.<a href='/auth/login'> cliquez ici pour vous connecter</a>"  "Une erreure est survenue lors de la validation de votre compte ";
  69.         return $this->render("auth/activated.html.twig", ["message"=> $message"success"=>$response["success"]]);
  70.     }
  71. }