<commit_before><?php
/**
 * Created by PhpStorm.
 * User: Thibault
 * Date: 10/02/2017
 * Time: 12:46
 */

namespace AppBundle\Controller;


use AppBundle\Entity\Credentials;
use AppBundle\Entity\User;
use AppBundle\Form\ProfileType;
use AppBundle\Form\UserType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

class AccountController extends Controller
{

    /**
     * @Route("/login", name="login")
     */
    public function loginAction()
    {
        $authenticationUtils = $this->get('security.authentication_utils');
        $error = $authenticationUtils->getLastAuthenticationError();
        $lastUsername = $authenticationUtils->getLastUsername();

        return $this->render('account/login.html.twig',array(
            "error" => $error,
            "lastUsername" => $lastUsername
        ));
    }

    /**
     * @Route("/register", name="register")
     */
    public function registerAction()
    {
        $form = $this->createForm(UserType::class, new User(), array('method' => 'POST', 'action' => $this->generateUrl('saveAccount')));
        return $this->render(':account:registration.html.twig',array(
            'form' => $form->createView()
        ));
    }

    /**
     * @Route("/registration/saveAccount", name="saveAccount")
     * @Method("POST")
     */
    public function saveAccountAction(Request $request)
    {
        $user = new User();
        $form = $this->createForm(UserType::class, $user);

        $form->handleRequest($request);<commit_msg>Upd: add redirection on /login and /register if connected<commit_after><?php
/**
 * Created by PhpStorm.
 * User: Thibault
 * Date: 10/02/2017
 * Time: 12:46
 */

namespace AppBundle\Controller;


use AppBundle\Entity\Credentials;
use AppBundle\Entity\User;
use AppBundle\Form\ProfileType;
use AppBundle\Form\UserType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;

class AccountController extends Controller
{

    /**
     * @Route("/login", name="login")
     */
    public function loginAction()
    {
        if($this->getUser() != null)
        {
            return $this->redirectToRoute('dashboard');
        }
        $authenticationUtils = $this->get('security.authentication_utils');
        $error = $authenticationUtils->getLastAuthenticationError();
        $lastUsername = $authenticationUtils->getLastUsername();

        return $this->render('account/login.html.twig',array(
            "error" => $error,
            "lastUsername" => $lastUsername
        ));
    }

    /**
     * @Route("/register", name="register")
     */
    public function registerAction()
    {
        if($this->getUser() != null)
        {
            return $this->redirectToRoute('dashboard');
        }
        $form = $this->createForm(UserType::class, new User(), array('method' => 'POST', 'action' => $this->generateUrl('saveAccount')));
        return $this->render(':account:registration.html.twig',array(
            'form' => $form->createView()
        ));
    }

    /**
     * @Route("/registration/saveAccount", name="saveAccount")
     * @Method("POST")
     */
    public function saveAccountAction(Request $request)
    {
        $user = new User();
        $form = $this->createForm(UserType::class, $user);

        $form->handleRequest($request);
{'fraction_non_alphanumeric': 0.1450587084148728, 'fraction_numerical': 0.005870841487279843, 'mean_word_length': 3.439739413680782, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '3623112', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1135, 'n_words': 191}