Advertisement
Guest User

Untitled

a guest
Mar 11th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. <?php
  2.  
  3. namespace ImmoWebBundle\Controller;
  4.  
  5. use ImmoWebBundle\Controller;
  6. use ImmoWebBundle\Entity\Person;
  7. use ImmoWebBundle\Form\PersonType;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  9. use Symfony\Component\HttpFoundation\Request;
  10.  
  11. class IndexController extends Controller
  12. {
  13.     /**
  14.      * @Route("/", name="home")
  15.      */
  16.     public function indexAction(Request $request)
  17.     {
  18.         // replace this example code with whatever you need
  19.         return $this->renderFrontend('index');
  20.     }
  21.  
  22.     /**
  23.      * @Route("/register", name="register")
  24.      */
  25.     public function registerAction(Request $request)
  26.     {
  27.  
  28.         $person = new Person();
  29.         $form = $this->createForm(PersonType::class, $person);
  30.  
  31.         $form->handleRequest($request);
  32.  
  33.         if ($form->isSubmitted() && $form->isValid()) {
  34.  
  35.             $password = $this->get('security.password_encoder')
  36.                 ->encodePassword($person, $person->getPlainPassword());
  37.             $person->setPassword($password);
  38.  
  39.             $em = $this->getDoctrine()->getManager();
  40.             $em->persist($person);
  41.             $em->flush();
  42.  
  43.             return $this->redirectToRoute('home');
  44.         }
  45.  
  46.         return $this->renderFrontend(
  47.             'register',
  48.             ['form' => $form->createView()]
  49.         );
  50.     }
  51.  
  52.     /**
  53.      * @Route("/login", name="login")
  54.      */
  55.     public function loginAction(Request $request)
  56.     {
  57.  
  58.  
  59.         $authenticationUtils = $this->get('security.authentication_utils');
  60.  
  61.         $error = $authenticationUtils->getLastAuthenticationError();
  62.         $lastUsername = $authenticationUtils->getLastUsername();
  63.  
  64.         return $this->renderFrontend('login', [
  65.             'last_username' => $lastUsername,
  66.             'error' => $error
  67.         ]);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement