<commit_before><?php

namespace Desymfony\DesymfonyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Desymfony\DesymfonyBundle\Form\UsuarioType;
use Symfony\Component\Security\Core\SecurityContext;

class UsuarioController extends Controller
{
    public function indexAction()
    {
        return $this->render('DesymfonyBundle:Usuario:index.html.twig');
    }

    public function loginAction()
    {
        if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
        }

        return $this->render('DesymfonyBundle:Usuario:login.html.twig', array(
            'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
            'error'         => $error,
        ));
    }

    public function loginCheckAction()
    {
        
    }

    public function logoffAction()
    {
        
    }

    public function perfilAction()
    {
        return $this->render('DesymfonyBundle:Usuario:perfil.html.twig');
    }

    public function registroAction()
    {

        $form = $this->get('form.factory')->create(new UsuarioType(), array());
        
        $request = $this->get('request');
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);

            if ($form->isValid()) {

                // Mensaje para notificar al usuario que todo ha salido bien
                $session = $this->get('request')->getSession();
                $session->setFlash('notice', 'Gracias por registrarte en Desymfony 2011');

                // Guardamos el objeto en base de datos
                $em = $this->get('doctrine.orm.entity_manager');
                $em->persist($form->getData());
                $em->flush();

                return $this->redirect($this->generateUrl('registro'));
            }
        }
        return $this->render('DesymfonyBundle:Usuario:registro.html.twig', array('form' => $form->createView()));
    }
}<commit_msg>[Issue #5] Cuando el usuario se registra se loguea automáticamente<commit_after><?php

namespace Desymfony\DesymfonyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Desymfony\DesymfonyBundle\Form\UsuarioType;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

class UsuarioController extends Controller
{
    public function indexAction()
    {
        return $this->render('DesymfonyBundle:Usuario:index.html.twig');
    }

    public function loginAction()
    {
        if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
            $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
        } else {
            $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
        }

        return $this->render('DesymfonyBundle:Usuario:login.html.twig', array(
            'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
            'error'         => $error,
        ));
    }

    public function loginCheckAction()
    {
        
    }

    public function logoffAction()
    {
        
    }

    public function perfilAction()
    {
        return $this->render('DesymfonyBundle:Usuario:perfil.html.twig');
    }

    public function registroAction()
    {

        $form = $this->get('form.factory')->create(new UsuarioType(), array());
        
        $request = $this->get('request');
        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);

            if ($form->isValid()) {

                // Mensaje para notificar al usuario que todo ha salido bien
                $session = $this->get('request')->getSession();
                $session->setFlash('notice', 'Gracias por registrarte en Desymfony 2011');

                // Guardamos el objeto en base de datos
                $entity = $form->getData();
                $em = $this->get('doctrine.orm.entity_manager');
                $em->persist($entity);
                $em->flush();

                // Logueamos al usuario
                $token = new UsernamePasswordToken(
                            $entity->getUsername(),
                            $entity->getPassword(),
                            'main',
                            $entity->getRoles()
                        );
                $this->get('security.context')->setToken($token);

                return $this->redirect($this->generateUrl('registro'));
            }
        }
        return $this->render('DesymfonyBundle:Usuario:registro.html.twig', array('form' => $form->createView()));
    }
}
{'fraction_non_alphanumeric': 0.143578352180937, 'fraction_numerical': 0.0018174474959612278, 'mean_word_length': 2.3376010781671157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4739404', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1342, 'n_words': 218}