<commit_before><?php

namespace Edukagames\UserBundle\Controller;

use Edukagames\UserBundle\Entity\Alumno;

use Edukagames\UserBundle\Form\AlumnoPerfilType;

use Symfony\Component\Security\Core\SecurityContext;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render('UserBundle:Base:index.html.twig');
    }
    
    public function loginAction() {
        $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('UserBundle:Base:loginBox.html.twig',array(
				// last username entered by the user
				'last_username' => $session->get(SecurityContext::LAST_USERNAME),
				'error' => $error)
		);
    }
    public function perfilAction()
    {
    	$token = $this->container->get('security.context')->getToken();
    	$userConnected = $token->getUser();
    	$rutaImagen = "bundles/user/img/".$userConnected->getId()."/".$userConnected->getFoto();
    	$formulario = $this->createForm(new AlumnoPerfilType(),$userConnected);
    	$passwordOriginal = $user<PASSWORD>();
    	$imagenOriginal = $userConnected->getFoto();
    	
    	if ($this->getRequest()->getMethod() == "POST") {
    		$formulario->bindRequest($this->getRequest());
    		if ($formulario->isValid()) {
    			$em = $this->getDoctrine()->getManager();
    			$alumno = $em->getRepository('UserBundle:Alumno')->find($userConnected->getId());
    			$passwordNoEncriptado = $formulario->getData()->getPassword();
    			$newUser = $formulario->getData()->getUserName();

    			if ($passwordNoEncriptado != null) {
    				$encoder = $this->get('security.encoder_factory')->getEncoder($alumno);
	    			$passwordCodificado = $encoder->encodePassword($passwordNoEncriptado, $alumno->getSalt());
	    			$alumno->setPassword($passwordCodificado);
    				$alumno->setUserName($newUser);
    			} else {
    				$alumno->setUserName($newUser);
    				$alumno->setPassword($passwordOriginal);
    			}
    			
    			if($formulario->getData()->getFoto() != null){
    				$nombreArchivo = $formulario->getData()->getFoto()->getClientOriginalName();
    				$alumno->setFoto($nombreArchivo);
    				$raizImagen = 'bundles/user/img/'.$userConnected->getId();
    				if(!file_exists($raizImagen)){
    					mkdir($raizImagen);
    				}
    				move_uploaded_file($_FILES['Alumno_Perfil']['tmp_name']["foto"], 'bundles/user/img/'.$userConnected->getId().'/'.$nombreArchivo);
    			}else {
    				$alumno->setFoto($imagenOriginal);
    			}

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

    			return $this->redirect($this->generateUrl('user_perfil_edit'));

    		}
    		
    	}
		
    	return $this->render('UserBundle:Default:perfil.html.twig', array(
    			'form' => $formulario->createView(),<commit_msg>[sprint 2] minor changes in controller, and it will be erased so...<commit_after><?php

namespace Edukagames\UserBundle\Controller;

use Edukagames\UserBundle\Util\SaveFile;

use Edukagames\UserBundle\Entity\Alumno;

use Edukagames\UserBundle\Form\AlumnoPerfilType;

use Symfony\Component\Security\Core\SecurityContext;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;


class DefaultController extends Controller
{
    public function indexAction()
    {
        return $this->render('UserBundle:Base:index.html.twig');
    }
    
    public function loginAction() {
        $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('UserBundle:Base:loginBox.html.twig',array(
				// last username entered by the user
				'last_username' => $session->get(SecurityContext::LAST_USERNAME),
				'error' => $error)
		);
    }
    public function perfilAction()
    {
    	$token = $this->container->get('security.context')->getToken();
    	$userConnected = $token->getUser();
    	$rutaImagen = "bundles/user/img/".$userConnected->getId()."/".$userConnected->getFoto();
    	$formulario = $this->createForm(new AlumnoPerfilType(),$userConnected);
    	$passwordOriginal = $<PASSWORD>();
    	$imagenOriginal = $userConnected->getFoto();
    	
    	if ($this->getRequest()->getMethod() == "POST") {
    		$formulario->bindRequest($this->getRequest());
    		if ($formulario->isValid()) {
    			$em = $this->getDoctrine()->getManager();
    			$alumno = $em->getRepository('UserBundle:Alumno')->find($userConnected->getId());
    			$passwordNoEncriptado = $formulario->getData()->getPassword();
    			$newUser = $formulario->getData()->getUserName();

    			if ($passwordNoEncriptado != null) {
    				$encoder = $this->get('security.encoder_factory')->getEncoder($alumno);
	    			$passwordCodificado = $encoder->encodePassword($passwordNoEncriptado, $alumno->getSalt());
	    			$alumno->setPassword($passwordCodificado);
    				$alumno->setUserName($newUser);
    			} else {
    				$alumno->setUserName($newUser);
    				$alumno->setPassword($passwordOriginal);
    			}
    			
    			if($formulario->getData()->getFoto() != null){
    				
    				$nombreArchivo = $formulario->getData()->getFoto()->getClientOriginalName();
//     				$alumno->setFoto($nombreArchivo);
    				$raizImagen = 'bundles/user/img/'.$userConnected->getId();
//     				if(!file_exists($raizImagen)){
//     					mkdir($raizImagen);
//     				}
//     				move_uploaded_file($_FILES['Alumno_Perfil']['tmp_name']["foto"], 'bundles/user/img/'.$userConnected->getId().'/'.$nombreArchivo);
    				SaveFile::saveFile($raizImagen, $_FILES['Alumno_Perfil']['tmp_name']["foto"], $nombreArchivo);
    			}else {
    				$alumno->setFoto($imagenOriginal);
    			}

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

    			return $this->redirect($this->generateUrl('user_perfil_edit'));

    		}
    		
    	}
		
    	return $this->render('UserBundle:Default:perfil.html.twig', array(
    			'form' => $formulario->createView(),
{'fraction_non_alphanumeric': 0.17274291973087152, 'fraction_numerical': 0.00015647003598810827, 'mean_word_length': 3.679355783308931, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 121, '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': '2558050', 'n_tokens_mistral': 2301, 'n_tokens_neox': 2158, 'n_words': 237}