<commit_before><?php
namespace Rotis\CourseMakerBundle\Controller;


use Rotis\CourseMakerBundle\Entity\Joueur;
use Rotis\CourseMakerBundle\Form\Model\PlayerAddition;
use Rotis\CourseMakerBundle\Form\Type\EditType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Rotis\CourseMakerBundle\Form\Type\RegistrationType;
use Rotis\CourseMakerBundle\Form\Model\Registration;
use Rotis\CourseMakerBundle\Form\Type\PlayerAdditionType;

class EquipeController extends Controller
{
    public function registerAction()
    {

           if (true === $this->get('security.context')->isGranted('ROLE_USER')) 
           {
               return $this->redirect($this->generateUrl('accueil'));
           }
           $form = $this->createForm(
            new RegistrationType(),
            new Registration()
        );
        return $this->render(
            'RotisCourseMakerBundle:Equipe:register.html.twig',
            array('form' => $form->createView())
        );
    }

    public function editAction($name)
    {
        $repository = $this->getDoctrine()
            ->getManager()
            ->getRepository('RotisCourseMakerBundle:Equipe');
        $em = $this->getDoctrine()->getEntityManager();
        $form = $this->createForm(new PlayerAdditionType(), new PlayerAddition());
        $equipe= $repository->findOneBy(array('username' => $name));
        if ($this->getRequest()->getMethod() == 'POST') {
            $form->bindRequest($this->getRequest());
        if ($form->isValid())
        {
            $factory = $this->get('security.encoder_factory');
            $registration = $form->getData();
            $joueur = $registration->getJoueur();

            /*
             $encoder = $factory->getEncoder($user);
            $password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
            $user->setPassword($password);
            $em->merge($user);
            $em->flush();
            $this->get('session')->setFlash(
                'notice',
                'Equipe modifiée!'
            );*/
            return $this->redirect($this->generateUrl('accueil'));
        }
        }

        return $this->render('RotisCourseMakerBundle:Equipe:edit_equipe.html.twig', array('equipe' => $equipe,'form' => $form->createView()));<commit_msg>Equipe can modify only themselves<commit_after><?php
namespace Rotis\CourseMakerBundle\Controller;


use Rotis\CourseMakerBundle\Entity\Joueur;
use Rotis\CourseMakerBundle\Form\Model\PlayerAddition;
use Rotis\CourseMakerBundle\Form\Type\EditType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Rotis\CourseMakerBundle\Form\Type\RegistrationType;
use Rotis\CourseMakerBundle\Form\Model\Registration;
use Rotis\CourseMakerBundle\Form\Type\PlayerAdditionType;

class EquipeController extends Controller
{
    public function registerAction()
    {
       if (true === $this->get('security.context')->isGranted('ROLE_USER')) {
           return $this->redirect($this->generateUrl('accueil'));
       }

       $form = $this->createForm(
        new RegistrationType(),
        new Registration()
    );

        return $this->render(
            'RotisCourseMakerBundle:Equipe:register.html.twig',
            array('form' => $form->createView())
        );
    }

    public function editAction($name)
    {

        $repository = $this->getDoctrine()
            ->getManager()
            ->getRepository('RotisCourseMakerBundle:Equipe');
        $em = $this->getDoctrine()->getEntityManager();
        $form = $this->createForm(new PlayerAdditionType(), new PlayerAddition());
        $equipe= $repository->findOneBy(array('username' => $name));

        if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')
            && true === $this->get('security.context')->isGranted('ROLE_USER')
            && (! method_exists($this->get('security.context')->getToken()->getUser(), 'getName')
            || $this->get('security.context')->getToken()->getUser()->getName() !== $name))
        {
            return $this->redirect($this->generateUrl('accueil'));
        }

        if ($this->getRequest()->getMethod() == 'POST') {
            $form->bindRequest($this->getRequest());

            if ($form->isValid())
            {
                $factory = $this->get('security.encoder_factory');
                $registration = $form->getData();
                $joueur = $registration->getJoueur();

                /*
                 $encoder = $factory->getEncoder($user);
                $password = $encoder->encodePassword($user->getPassword(), $user->getSalt());
                $user->setPassword($password);
                $em->merge($user);
                $em->flush();
                $this->get('session')->setFlash(
                    'notice',
                    'Equipe modifiée!'
                );*/
                return $this->redirect($this->generateUrl('accueil'));
            }
        }

        return $this->render('RotisCourseMakerBundle:Equipe:edit_equipe.html.twig', array('equipe' => $equipe,'form' => $form->createView()));
{'fraction_non_alphanumeric': 0.15807237952372022, 'fraction_numerical': 0.0, 'mean_word_length': 2.6710254645560907, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 94, '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': '2273823', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1443, 'n_words': 198}