<commit_before><?php

/**
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Bundle\DoctrineUserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller as Controller;
use Bundle\DoctrineUserBundle\DAO\User;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * RESTful controller managing user CRUD
 */
class UserController extends Controller
{
    /**
     * Show all users
     **/
    public function listAction()
    {
        $users = $this['doctrine_user.user_repository']->findAll();

        return $this->render('DoctrineUserBundle:User:list:'.$this->getRenderer(), array('users' => $users));
    }

    /**
     * Show one user
     */
    public function showAction($username)
    {
        $user = $this->findUser($username);

        return $this->render('DoctrineUserBundle:User:show:'.$this->getRenderer(), array('user' => $user));
    }

    /**
     * Edit one user, show the edit form
     */
    public function editAction($username)
    {
        $user = $this->findUser($username);
        $form = $this->createForm('doctrine_user_user_edit', $user);

        return $this->render('DoctrineUserBundle:User:edit:'.$this->getRenderer(), array('form' => $form, 'username' => $username));
    }

    /**
     * Update a user
     */
    public function updateAction($username)
    {
        $user = $this->findUser($username);
        $form = $this->createForm('doctrine_user_user_edit', $user);

        if($data = $this['request']->request->get($form->getName())) {
            $form->bind($data);
            if($form->isValid()) {
                $this->saveUser($user);
                $this['session']->setFlash('doctrine_user_user_update/success', true);
                $userUrl = $this->generateUrl('doctrine_user_user_show', array('username' => $user->getUsername()));
                return $this->redirect($userUrl);
            }
        }

        return $this->render('DoctrineUserBundle:User:edit:'.$this->getRenderer(), array('form' => $form, 'username' => $username));
    }

    /**
     * Show the new form
     */
    public function newAction()
    {
        $form = $this->createForm('doctrine_user_user_new');

        return $this->render('DoctrineUserBundle:User:new:'.$this->getRenderer(), array('form' => $form));
    }

    /**
     * Create a user
     */
    public function createAction()
    {
        $form = $this->createForm('doctrine_user_user_new');
        $form->bind($this['request']->request->get($form->getName()));

        if($form->isValid()) {
            $user = $form->getData();
            $user->setIsActive(false);
            $this->saveUser($user);
            $this->sendConfirmationEmail($user);
            $this['session']->setFlash('doctrine_user_user_create/success', true);
            // store created user username in session
            $this['session']->set('doctrine_user/check_email/username', $user->getUsername());

            return $this->redirect($this->generateUrl('doctrine_user_user_check_email'));
        }

        return $this->render('DoctrineUserBundle:User:new:'.$this->getRenderer(), array('form' => $form));
    }

    protected function sendConfirmationEmail(User $user)
    {
        $parameters = $this->container->getParameter('doctrine_user.confirmation_email.parameters');
        
        // Render the template, use the first line as the subject, and the rest as the body
        $rendered = $this->renderView($parameters['template'].':'.$this->getRenderer(), array(
            'user' => $user,
            'confirmationUrl' => $this->generateUrl('doctrine_user_user_confirm', array('token' => $user->getConfirmationToken()), true)
        ));
        $renderedLines = explode("\n", $rendered);
        $subject = $renderedLines[0];
        $body = implode("\n", array_slice($renderedLines, 1));

	    $message = \Swift_Message::newInstance()
	        ->setSubject($subject)
	        ->setFrom($parameters['from'])
	        ->setTo($user->getEmail())
	        ->setBody($body);

	    $this['mailer']->send($message);
    }

    public function checkEmailAction()
    {
        $user = $this->findUser($this['session']->get('doctrine_user/check_email/username'));

        return $this->render('DoctrineUserBundle:User:checkEmail:'.$this->getRenderer(), array('user' => $user));
    }

    /**
     * Delete one user
     */<commit_msg>Improve phpDoc in UserController<commit_after><?php

/**
 * (c) <NAME> <<EMAIL>>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Bundle\DoctrineUserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller as Controller;
use Bundle\DoctrineUserBundle\DAO\User;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * RESTful controller managing user CRUD
 */
class UserController extends Controller
{
    /**
     * Show all users
     **/
    public function listAction()
    {
        $users = $this['doctrine_user.user_repository']->findAll();

        return $this->render('DoctrineUserBundle:User:list:'.$this->getRenderer(), array('users' => $users));
    }

    /**
     * Show one user
     */
    public function showAction($username)
    {
        $user = $this->findUser($username);

        return $this->render('DoctrineUserBundle:User:show:'.$this->getRenderer(), array('user' => $user));
    }

    /**
     * Edit one user, show the edit form
     */
    public function editAction($username)
    {
        $user = $this->findUser($username);
        $form = $this->createForm('doctrine_user_user_edit', $user);

        return $this->render('DoctrineUserBundle:User:edit:'.$this->getRenderer(), array('form' => $form, 'username' => $username));
    }

    /**
     * Update a user
     */
    public function updateAction($username)
    {
        $user = $this->findUser($username);
        $form = $this->createForm('doctrine_user_user_edit', $user);

        if($data = $this['request']->request->get($form->getName())) {
            $form->bind($data);
            if($form->isValid()) {
                $this->saveUser($user);
                $this['session']->setFlash('doctrine_user_user_update/success', true);
                $userUrl = $this->generateUrl('doctrine_user_user_show', array('username' => $user->getUsername()));
                return $this->redirect($userUrl);
            }
        }

        return $this->render('DoctrineUserBundle:User:edit:'.$this->getRenderer(), array('form' => $form, 'username' => $username));
    }

    /**
     * Show the new form
     */
    public function newAction()
    {
        $form = $this->createForm('doctrine_user_user_new');

        return $this->render('DoctrineUserBundle:User:new:'.$this->getRenderer(), array('form' => $form));
    }

    /**
     * Create a user and send a confirmation email
     */
    public function createAction()
    {
        $form = $this->createForm('doctrine_user_user_new');
        $form->bind($this['request']->request->get($form->getName()));

        if($form->isValid()) {
            $user = $form->getData();
            $user->setIsActive(false);
            $this->saveUser($user);
            $this->sendConfirmationEmail($user);
            $this['session']->setFlash('doctrine_user_user_create/success', true);
            // store created user username in session
            $this['session']->set('doctrine_user/check_email/username', $user->getUsername());

            return $this->redirect($this->generateUrl('doctrine_user_user_check_email'));
        }

        return $this->render('DoctrineUserBundle:User:new:'.$this->getRenderer(), array('form' => $form));
    }

    /**
     * Send the confirmation email containing a link to the confirmation page, with a token
     */
    protected function sendConfirmationEmail(User $user)
    {
        $parameters = $this->container->getParameter('doctrine_user.confirmation_email.parameters');
        
        // Render the template, use the first line as the subject, and the rest as the body
        $rendered = $this->renderView($parameters['template'].':'.$this->getRenderer(), array(
            'user' => $user,
            'confirmationUrl' => $this->generateUrl('doctrine_user_user_confirm', array('token' => $user->getConfirmationToken()), true)
        ));
        $renderedLines = explode("\n", $rendered);
        $subject = $renderedLines[0];
        $body = implode("\n", array_slice($renderedLines, 1));

	    $message = \Swift_Message::newInstance()
	        ->setSubject($subject)
	        ->setFrom($parameters['from'])
	        ->setTo($user->getEmail())
	        ->setBody($body);

	    $this['mailer']->send($message);
    }

    /**
     * Tell the user to check his email provider
     */
    public function checkEmailAction()
    {
        $user = $this->findUser($this['session']->get('doctrine_user/check_email/username'));

        return $this->render('DoctrineUserBundle:User:checkEmail:'.$this->getRenderer(), array('user' => $user));
    }

    /**
     * Delete one user
     */
{'fraction_non_alphanumeric': 0.1676445023902651, 'fraction_numerical': 0.000434593654932638, 'mean_word_length': 2.888888888888889, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 155, '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': '6933027', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2594, 'n_words': 474}