Advertisement
Guest User

Untitled

a guest
Sep 15th, 2011
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Acme\SecurityBundle\Controller;
  4.  
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Symfony\Component\Security\Core\SecurityContext;
  7. use Acme\UserBundle\Entity\User;
  8. use Symfony\Component\HttpFoundation\Request;
  9.  
  10. class SecurityController extends Controller
  11. {
  12.     public function loginFormAction()
  13.     {
  14.         $Request = $this->getRequest();
  15.         $Session = $Request->getSession();
  16.        
  17.         if ($Request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
  18.             $error = $Request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
  19.         } else {
  20.             $error = $Session->get(SecurityContext::AUTHENTICATION_ERROR);
  21.         }
  22.        
  23.         return $this->render('AcmeSecurityBundle:Default:login_form.html.twig', array(
  24.             'error' => $error
  25.         ));
  26.     }
  27.    
  28.     public function registerAction(Request $request){
  29.         $user = new User();
  30.         $form = $this->createFormBuilder($user)
  31.             ->add('first_name', 'text')
  32.             ->add('last_name', 'text')
  33.             ->add('email', 'text')
  34.             ->add('password', 'password')
  35.             ->add('role', 'choice', array(
  36.                 'choices' => array(
  37.                     'Студент',
  38.                     'Преподаватель'
  39.                 )
  40.             ))
  41.             ->getForm();
  42.            
  43.         if ($request->getMethod() == 'POST'){ // register form submitted
  44.             $form->bindRequest($request);
  45.             if ($form->isValid()){
  46.                 $user->save($this);
  47.                 return $this->redirect($this->generateUrl('user_added'));
  48.             }
  49.         }
  50.        
  51.         return $this->render('AcmeSecurityBundle:Default:register_form.html.twig', array(
  52.             'form' => $form->createView()
  53.         ));
  54.     }
  55.    
  56.     public function userAddedAction(){
  57.         return $this->render('AcmeSecurityBundle:Default:user_added.htm.twig');
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement