Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Acme\SecurityBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\Security\Core\SecurityContext;
- use Acme\UserBundle\Entity\User;
- use Symfony\Component\HttpFoundation\Request;
- class SecurityController extends Controller
- {
- public function loginFormAction()
- {
- $Request = $this->getRequest();
- $Session = $Request->getSession();
- if ($Request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
- $error = $Request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
- } else {
- $error = $Session->get(SecurityContext::AUTHENTICATION_ERROR);
- }
- return $this->render('AcmeSecurityBundle:Default:login_form.html.twig', array(
- 'error' => $error
- ));
- }
- public function registerAction(Request $request){
- $user = new User();
- $form = $this->createFormBuilder($user)
- ->add('first_name', 'text')
- ->add('last_name', 'text')
- ->add('email', 'text')
- ->add('password', 'password')
- ->add('role', 'choice', array(
- 'choices' => array(
- 'Студент',
- 'Преподаватель'
- )
- ))
- ->getForm();
- if ($request->getMethod() == 'POST'){ // register form submitted
- $form->bindRequest($request);
- if ($form->isValid()){
- $user->save($this);
- return $this->redirect($this->generateUrl('user_added'));
- }
- }
- return $this->render('AcmeSecurityBundle:Default:register_form.html.twig', array(
- 'form' => $form->createView()
- ));
- }
- public function userAddedAction(){
- return $this->render('AcmeSecurityBundle:Default:user_added.htm.twig');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement