<commit_before><?php

namespace FrontBundle\Controller;

use CoreBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class UserController extends Controller
{
    public function registerAction(Request $request){
        $em= $this->getDoctrine()->getManager();

        if($em->getRepository('CoreBundle:User')->findOneBy(array('email'=>$request->get('email'))) or !$request->get('email')){
            $json = array();
            $json['success'] = false;
            $json['response']= 'Registration failed';

            return new JsonResponse($json);
        }

        $user = new User();
        $user->setUsername($request->get('username'));
        $user->setEmail($request->get('email'));
        $user->setPassword('<PASSWORD>');
        $user->setFirstname($request->get('firstname'));

        $em->persist($user);
        $em->flush();

        $json = array();
        $json['success'] = true;
        $json['response']= 'Registration done';
        $json['uid'] = $user->getUid();

        return new JsonResponse($json);
    }

    public function loginAction(){
        $authenticationUtils = $this->get('security.authentication_utils');
        
        return $this->render('@Front/User/login.html.twig', array(
            'last_username' => $authenticationUtils->getLastUsername(),
            'error'         => $authenticationUtils->getLastAuthenticationError(),
        ));
    }















//    /**
//     * @param Request $request
//     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response<commit_msg>Add login<commit_after><?php

namespace FrontBundle\Controller;

use CoreBundle\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class UserController extends Controller
{
    public function registerAction(Request $request){
        $em= $this->getDoctrine()->getManager();

        if($em->getRepository('CoreBundle:User')->findOneBy(array('email'=>$request->get('email'))) or !$request->get('email')){
            $json = array();
            $json['success'] = false;
            $json['response']= 'Registration failed';

            return new JsonResponse($json);
        }

        $user = new User();
        $user->setUsername($request->get('username'));
        $user->setEmail($request->get('email'));
        $user->setPassword('<PASSWORD>');
        $user->setFirstname($request->get('firstname'));

        $em->persist($user);
        $em->flush();

        $json = array();
        $json['success'] = true;
        $json['response']= 'Registration done';
        $json['uid'] = $user->getUid();

        return new JsonResponse($json);
    }

    public function loginAction(Request $request){
        $em= $this->getDoctrine()->getManager();

        if(!$em->getRepository('CoreBundle:User')->findOneBy(array('email'=>$request->get('email'))) or !$request->get('email')){
            $json = array();
            $json['success'] = false;
            $json['response']= 'Login failed';

            return new JsonResponse($json);
        }

        $user = $em->getRepository('CoreBundle:User')->findOneBy(array('email'=>$request->get('email')));

        $json = array();
        $json['success'] = true;
        $json['uid'] = $user->getUid();

        return new JsonResponse($json);
    }















//    /**
//     * @param Request $request
//     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
{'fraction_non_alphanumeric': 0.1721419185282523, 'fraction_numerical': 0.0, 'mean_word_length': 3.031779661016949, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 57, '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': '1360837', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1019, 'n_words': 166}