<?php
namespace App\Controller;
use App\Entity\User;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Twig\Environment;
class SecurityController extends AbstractController
{
private $twig;
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
/**
* @Route("/login", name="app_login")
*/
public function login(Request $request, AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/index.html.twig',
['last_username' => $lastUsername, 'error' => $error]);
}
/**
* @Route("/logout", name="app_logout", methods={"GET"})
*/
public function logout()
{
}
function changePass($id, $pass, $passwordEncoder)
{
$em = $this->getDoctrine()->getManager();
$userId = $em->getRepository(User::class)->find($id);
$userId->setPassword($passwordEncoder->hashPassword($userId, $pass));
$em->flush();
return true;
}
}