|
@@ -14,8 +14,8 @@ use Symfony\Component\HttpFoundation\Request;
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
use App\Form\UserType;
|
|
|
use App\Entity\User;
|
|
|
+use App\Repository\UserRepository;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
-use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
@@ -47,7 +47,7 @@ class SecurityController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/admin/createuser", name="admin_createuser")
|
|
|
*/
|
|
|
- public function createUserAction(Request $request, UserManager $userManager, UserPasswordEncoderInterface $encoder)
|
|
|
+ public function createUserAction(Request $request, UserManager $userManager)
|
|
|
{
|
|
|
$user = new User;
|
|
|
$form = $this->createForm(UserType::class, $user);
|
|
@@ -85,10 +85,8 @@ class SecurityController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/admin", name="admin_index")
|
|
|
*/
|
|
|
- public function indexAction(Request $request)
|
|
|
+ public function indexAction(Request $request, UserRepository $repo)
|
|
|
{
|
|
|
- $em = $this->getDoctrine()->getManager();
|
|
|
- $repo = $em->getRepository('App:User');
|
|
|
$users = $repo->findAll();
|
|
|
|
|
|
return $this->render('security/liste.html.twig', array(
|
|
@@ -99,13 +97,12 @@ class SecurityController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/admin/deluser/{id}", name="admin_deluser")
|
|
|
*/
|
|
|
- public function delUserAction (Request $request, User $user, EntityManagerInterface $em)
|
|
|
+ public function delUserAction (Request $request, User $user, UserManager $userManager)
|
|
|
{
|
|
|
$form = $this->get('form.factory')->create();
|
|
|
$form->handleRequest($request);
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
- $em->remove($user);
|
|
|
- $em->flush();
|
|
|
+ $userManager->removeUser($user);
|
|
|
$this->addFlash("success", "L'utilisateur a bien été supprimé");
|
|
|
return $this->redirectToRoute('admin_index');
|
|
|
}
|
|
@@ -118,20 +115,14 @@ class SecurityController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/register", name="security_register")
|
|
|
*/
|
|
|
- public function registerAction(Request $request, UserPasswordEncoderInterface $encoder, UserManager $userManager, Mail $mail, EntityManagerInterface $em)
|
|
|
+ public function registerAction(Request $request, UserManager $userManager, Mail $mail)
|
|
|
{
|
|
|
$user = new User();
|
|
|
- $user->setActivated(false);
|
|
|
$form = $this->createForm(UserRegisterType::class, $user);
|
|
|
$form->handleRequest($request);
|
|
|
if ($form->isSubmitted() && $form->isValid())
|
|
|
{
|
|
|
- $user->setRoles(array('ROLE_USER'));
|
|
|
- $encoded = $encoder->encodePassword($user, $user->getPassword());
|
|
|
- $user->setPassword($encoded);
|
|
|
- $userManager->generateToken($user);
|
|
|
- $em->persist($user);
|
|
|
- $em->flush();
|
|
|
+ $userManager->register($user);
|
|
|
|
|
|
$adresse = $this->generateUrl('security_activate', array('token'=>$user->getToken()), UrlGeneratorInterface::ABSOLUTE_URL);
|
|
|
|
|
@@ -182,17 +173,14 @@ class SecurityController extends AbstractController
|
|
|
/**
|
|
|
* @Route("/resetpassword/token={token}", name="security_resetpassword")
|
|
|
*/
|
|
|
- public function resetPasswordAction(Request $request, UserPasswordEncoderInterface $encoder, UserManager $userManager, EntityManagerInterface $em, User $user = null)
|
|
|
+ public function resetPasswordAction(Request $request, UserManager $userManager, User $user = null)
|
|
|
{
|
|
|
if ($user != null) {
|
|
|
if ($user->isValidToken()) {
|
|
|
$form = $this->createForm(UserEditPasswordType::class, $user);
|
|
|
$form->handleRequest($request);
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
- $encoded = $encoder->encodePassword($user, $user->getPassword());
|
|
|
- $user->setPassword($encoded);
|
|
|
- $userManager->generateToken($user);
|
|
|
- $em->flush();
|
|
|
+ $userManager->resetPassword($user);
|
|
|
$this->addFlash('success', 'Mot de passe changé, veuillez vous connecter');
|
|
|
return $this->redirectToRoute('videotheque_liste');
|
|
|
}
|