|
@@ -2,14 +2,18 @@
|
|
|
|
|
|
namespace AppBundle\Controller;
|
|
namespace AppBundle\Controller;
|
|
|
|
|
|
|
|
+use AppBundle\Form\UserEditPasswordType;
|
|
use AppBundle\Form\UserEditType;
|
|
use AppBundle\Form\UserEditType;
|
|
use AppBundle\Form\UserRegisterType;
|
|
use AppBundle\Form\UserRegisterType;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\SearchType;
|
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use AppBundle\Form\UserType;
|
|
use AppBundle\Form\UserType;
|
|
use AppBundle\Entity\User;
|
|
use AppBundle\Entity\User;
|
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
|
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
|
|
|
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
|
|
class SecurityController extends Controller
|
|
class SecurityController extends Controller
|
|
{
|
|
{
|
|
@@ -147,10 +151,68 @@ class SecurityController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @Route("/resetpassword/{token}", name="security_resetpassword")
|
|
|
|
|
|
+ * @Route("/motdepasseoublie", name="security_envoyertoken")
|
|
*/
|
|
*/
|
|
- public function resetPasswordAction(User $user)
|
|
|
|
|
|
+ public function recupMdpAction(Request $request, \Swift_Mailer $mailer)
|
|
{
|
|
{
|
|
|
|
+ $form = $this->createFormBuilder()
|
|
|
|
+ ->add('email', SearchType::class)
|
|
|
|
+ ->add('Envoyer mail', SubmitType::class)
|
|
|
|
+ ->getForm();
|
|
|
|
+
|
|
|
|
+ $form->handleRequest($request);
|
|
|
|
+ if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
|
+ $data = $form->getData();
|
|
|
|
+ $user = $em->getRepository('AppBundle:User')->findOneBy(array('mail'=>$data['email']));
|
|
|
|
+ if ($user != null)
|
|
|
|
+ {
|
|
|
|
+ $user->setToken();
|
|
|
|
+ $em->flush();
|
|
|
|
+ $adresse = $this->generateUrl('security_resetpassword', array('token'=>$user->getToken()), UrlGeneratorInterface::ABSOLUTE_URL);
|
|
|
|
+ $swiftMessage = new \Swift_Message('Videothèque - Mot de passe oublié');
|
|
|
|
+ $message = $swiftMessage
|
|
|
|
+ ->setFrom('admin@fdlibre.eu')
|
|
|
|
+ ->setTo($user->getMail())
|
|
|
|
+ ->setBody("Salut ".$user->getUsername().", clique sur ce lien pour renouveller ton mot de passe : ". $adresse);
|
|
|
|
+
|
|
|
|
+ $mailer->send($message);
|
|
|
|
+ $this->addFlash('success', "Un mail vous a été envoyé à ".$user->getUsername()." pour récupérer le mot de passe");
|
|
|
|
+ return $this->redirectToRoute('login');
|
|
|
|
+ } else {
|
|
|
|
+ $this->addFlash('warning', "Cet email n'existe pas");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return $this->render('@App/security/chercheruserpourpassword.html.twig', array (
|
|
|
|
+ 'form' => $form->createView()
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Route("/resetpassword/token={token}", name="security_resetpassword")
|
|
|
|
+ */
|
|
|
|
+ public function resetPasswordAction(Request $request, UserPasswordEncoderInterface $encoder, 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);
|
|
|
|
+ $user->setToken();
|
|
|
|
+ $em = $this->getDoctrine()->getManager();
|
|
|
|
+ $em->flush();
|
|
|
|
+ $this->addFlash('success', 'Mot de passe changé, veuillez vous connecter');
|
|
|
|
+ return $this->redirectToRoute('videotheque_liste');
|
|
|
|
+ }
|
|
|
|
+ return $this->render('@App/security/password.html.twig', array(
|
|
|
|
+ 'form' => $form->createView()
|
|
|
|
+ ));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $this->addFlash('warning', "Ce token n'est plus valide");
|
|
|
|
+ return $this->redirectToRoute('videotheque_liste');
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|