<?php
namespace App\Controller;
use App\Services\ApiService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class AuthController
* @package App\Controller
*@Route("/auth")
*/
class AuthController extends AbstractController
{
/**
* @var ApiService
*/
private $apiService;
public function __construct(ApiService $apiService)
{
$this->apiService = $apiService;
}
/**
* @Route("/login",name="app_login",methods={"POST","GET"})
*/
public function loginAction(){
return $this->render("auth/login.html.twig");
}
/**
* @Route("/reset-password",name="app_reset_password",methods={"GET"})
*/
public function ResetPasswordAction(){
return $this->render("auth/reset_password.html.twig");
}
/**
* @Route("/updated-password",name="app_updated_password",methods={"GET"})
*/
public function UpdatedPasswordAction(Request $request){
$error = null;
$email = null ;
try{
$token = $request->query->get("token");
if (empty($token))
$error = "token invalide";
if (!$error) {
$response = $this->apiService->verifyToken($token);
$email = $response["response"] ? $response["response"]["email"] : null ;
if ($response["error"])
$error =$response["error"];
}
}catch (\Exception $exception){
$error = $exception->getMessage();
}
$template = !$error ? "auth/updated_password.html.twig":"error/error500.html.twig";
return $this->render($template,["error"=>$error,"email"=>$email]);
}
/**
* @Route("/registration",name="app_registration",methods={"POST","GET"})
*/
public function RegistrationAction(){
return $this->render("auth/registration.html.twig");
}
/**
* @Route("/activated",name="app_activation_compte",methods={"GET"})
*/
public function activatedAction(Request $request){
$token = $request->query->get("token");
$response = $this->apiService->activatedUser($token);
$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 ";
return $this->render("auth/activated.html.twig", ["message"=> $message, "success"=>$response["success"]]);
}
}