François 6 gadi atpakaļ
vecāks
revīzija
981a9185a4

+ 7 - 2
src/AppBundle/Controller/SecurityController.php

@@ -38,7 +38,6 @@ class SecurityController extends Controller
         $form->handleRequest($request);
         if ($form->isSubmitted() && $form->isValid())
         {
-            $user = $form->getData();
             $encoded = $encoder->encodePassword($user, $user->getPassword());
             $user->setPassword($encoded);
             $em = $this->getDoctrine()->getManager();
@@ -62,7 +61,6 @@ class SecurityController extends Controller
         if ($form->isSubmitted() && $form->isValid())
         {
             $em = $this->getDoctrine()->getManager();
-            $user = $form->getData();
             $em->flush();
             $this->addFlash('success', 'L\'utilisateur a été modifié');
             return $this->redirectToRoute('admin_index');
@@ -148,5 +146,12 @@ class SecurityController extends Controller
         return $this->redirectToRoute('admin_index');
     }
 
+    /**
+     * @Route("/resetpassword/{token}", name="security_resetpassword")
+     */
+    public function resetPasswordAction(User $user)
+    {
+
+    }
 
 }

+ 75 - 0
src/AppBundle/Entity/User.php

@@ -58,6 +58,20 @@ class User implements UserInterface
      */
     private $password;
 
+    /**
+     * @var string
+     *
+     * @ORM\Column(name="token", type="string", length=255)
+     */
+    private $token;
+
+    /**
+     * @var \DateTime
+     *
+     * @ORM\Column(name="token_validity", type="datetime")
+     */
+    private $tokenValidity;
+
     /**
      * @var string
      *
@@ -249,6 +263,67 @@ class User implements UserInterface
         return $this->salt;
     }
 
+    /**
+     * Get token
+     *
+     * @return string
+     */
+    public function getToken()
+    {
+        return $this->token;
+    }
+
+    /**
+     * Set token
+     *
+     * @return User
+     */
+    public function setToken()
+    {
+        $this->token = hash("sha512", uniqid());
+        $this->setTokenValidity(new \DateTime());
+
+        return $this;
+    }
+
+    /**
+     * Get token_validity
+     *
+     * @return string
+     */
+    public function getTokenValidity()
+    {
+        return $this->tokenValidity;
+    }
+
+    /**
+     * Set token
+     *
+     * @param string $tokenValidity
+     *
+     * @return User
+     */
+    private function setTokenValidity($tokenValidity)
+    {
+        $this->tokenValidity = $tokenValidity;
+
+        return $this;
+    }
+
+    /**
+     * Is ValidToken
+     *
+     * @return boolean
+     *
+     */
+
+    public function isValidToken()
+    {
+        $delay = new \DateTime('1 hour');
+
+        return ( $this->getTokenValidity() < $delay );
+    }
+
     /**
      * Set roles
      *