Advertisement
Guest User

AccountController

a guest
Nov 5th, 2013
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2. // src/Acme/AccountBundle/Controller/AccountController.php
  3. namespace Acme\AccountBundle\Controller;
  4.  
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\Request;
  8.  
  9. use Acme\AccountBundle\Form\Type\RegistrationType;
  10. use Acme\AccountBundle\Form\Model\Registration;
  11. //use Acme\AccountBundle\Entity\User;
  12. //use Acme\AccountBundle\Entity\Role;
  13.  
  14. class AccountController extends Controller
  15. {
  16.    
  17.    
  18.     public function createAction(Request $request)
  19.     {  
  20.        
  21.     $em = $this->getDoctrine()->getManager();
  22.    
  23.     $registrationForm = $this->createForm(new RegistrationType(), new Registration());
  24.  
  25.     $registrationForm->handleRequest($request);
  26.    
  27.  
  28.     if ($registrationForm->isValid()) {
  29.        
  30.         $registration = $registrationForm->getData();
  31.        
  32.        
  33.         $user = $registration->getUser();
  34.        
  35.         $user->setSalt($this->generateSalt());
  36.         $user->setIsActive(1);
  37.        
  38.    
  39.        
  40.         $factory = $this->get('security.encoder_factory');
  41.  
  42.         $encoder = $factory->getEncoder($user);
  43.         $password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
  44.            
  45.         $user->setPassword($password);
  46.        
  47.         $em->persist($user);
  48.         $em->flush();
  49.        
  50.         return $this->redirect($this->generateUrl('acme_front_homepage'));
  51.     }
  52.    
  53.  
  54.     return $this->render(
  55.         'AcmeFrontBundle:Registration:register.html.php',
  56.         array('registrationForm' => $registrationForm->createView())
  57.     );
  58. }
  59.  
  60.  
  61.     /*
  62.      * vygeneruje sul na hashovani hesla
  63.      */
  64.      public function generateSalt($len = 6){    
  65.     $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';                      
  66.     $salt = '';                      
  67.     for ($i=0; $i < $len; $i++) {
  68.         $salt .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
  69.     }
  70.          return $salt;
  71.      }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement