Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.58 KB | None | 0 0
  1. /**
  2.      * @Route("/SignUp", name="wx_exchange_signup")
  3.      * @Template("WXExchangeBundle:User:signup.html.twig")
  4.      * User sign up - Open to public
  5.      * Creates new users based on information they provide
  6.      */
  7.     public function signupAction()
  8.     {
  9.         $registration = new Registration();
  10.         $form = $this->createForm(new RegistrationType(), $registration, array(
  11.             'action' => $this->generateUrl('wx_exchange_signup_create'),
  12.         ));
  13.  
  14.         return array('form' => $form->createView());
  15.     }
  16.    
  17.     /**
  18.      * @Route("/SignUp/create", name="wx_exchange_signup_create")
  19.      * @Template("WXExchangeBundle:User:signup.html.twig")
  20.      * User sign up - Open to public
  21.      * Creates new users based on information they provide
  22.      */
  23.     public function signupCreateAction(Request $request)
  24.     {
  25.         $em = $this->getDoctrine()->getManager();
  26.  
  27.         $form = $this->createForm(new RegistrationType(), new Registration());
  28.  
  29.         $form->handleRequest($request);
  30.  
  31.         if ($form->isValid()) {
  32.             $registration = $form->getData();
  33.            
  34.             $factory = $this->get('security.encoder_factory');
  35.            
  36.             $user = $registration->getUser();
  37.             $user->setUserip($this->container->get('request')->getClientIp(););
  38.            
  39.             $encoder = $factory->getEncoder($user);
  40.             $password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
  41.            
  42.             $user->setPassword($password);
  43.  
  44.             $em->persist($user);
  45.             $em->flush();
  46.  
  47.             return $this->redirect($this->generateUrl("wx_exchange_default_index"));
  48.         }
  49.  
  50.         return array('form' => $form->createView());
  51.     }
  52.    
  53.     /**
  54.      * @Route("/Login", name="wx_exchange_login")
  55.      * @Template("WXExchangeBundle:User:login.html.twig")
  56.      * User login - Open to public
  57.      * Authenticates users to the system
  58.      */
  59.     public function loginAction(Request $request)
  60.     {
  61.         $session = $request->getSession();
  62.  
  63.         // get the login error if there is one
  64.         if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
  65.             $error = $request->attributes->get(
  66.                 SecurityContext::AUTHENTICATION_ERROR
  67.             );
  68.         } else {
  69.             $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
  70.             $session->remove(SecurityContext::AUTHENTICATION_ERROR);
  71.         }
  72.  
  73.         return $this->render(
  74.             'WXExchangeBundle:User:login.html.twig',
  75.             array(
  76.                 // last username entered by the user
  77.                 'last_username' => $session->get(SecurityContext::LAST_USERNAME),
  78.                 'error'         => $error,
  79.             )
  80.         );
  81.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement