<commit_before><?php

namespace User\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use User\Form\DeleteAuthorizedAppType;
use App\Entity\User;
use User\Form\ChangePasswordType;
use User\Form\EditEmailAddressType;
use App\Entity\EmailAddress;
use User\Form\EmailAddressType;

class ProfileController extends Controller
{
    /**
     * @Template
     */
    public function indexAction()
    {
        return array(
            'data'=>$this->getUser(),
            'form' => array(
                'add_email' => $this->createForm(new EmailAddressType())->createView(),
            ),
        );
    }

    /**
     * @Template
     * Internal action, not exposed in a route
     */
    public function removeAuthorizedAppAction($appId)
    {
        return $this->createForm(new DeleteAuthorizedAppType(), array('id'=>$appId));
    }

    public function deleteAuthorizedAppAction(Request $request)
    {
        $form = $this->createForm(new DeleteAuthorizedAppType());

        $form->handleRequest($request);

        if($form->isValid()) {
            $appId = $form->get('id')->getData();
            $client = $this->getDoctrine()
                ->getRepository('AppBundle:OAuth\Client')
                ->find($appId);

            if($client && ($user = $this->getUser()) && $user instanceof User) {
                $user->removeAuthorizedApplication($client);
                $this->getDoctrine()->getRepository('AppBundle:User')->update($user);
                $this->get('braincrafted_bootstrap.flash')->success('Authorized application has been removed');<commit_msg>Remove all refresh tokens and access tokens when an app gets deleted by the user.<commit_after><?php

namespace User\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use User\Form\DeleteAuthorizedAppType;
use App\Entity\User;
use User\Form\ChangePasswordType;
use User\Form\EditEmailAddressType;
use App\Entity\EmailAddress;
use User\Form\EmailAddressType;

class ProfileController extends Controller
{
    /**
     * @Template
     */
    public function indexAction()
    {
        return array(
            'data'=>$this->getUser(),
            'form' => array(
                'add_email' => $this->createForm(new EmailAddressType())->createView(),
            ),
        );
    }

    /**
     * @Template
     * Internal action, not exposed in a route
     */
    public function removeAuthorizedAppAction($appId)
    {
        return $this->createForm(new DeleteAuthorizedAppType(), array('id'=>$appId));
    }

    public function deleteAuthorizedAppAction(Request $request)
    {
        $form = $this->createForm(new DeleteAuthorizedAppType());

        $form->handleRequest($request);

        if($form->isValid()) {
            $appId = $form->get('id')->getData();
            $client = $this->getDoctrine()
                ->getRepository('AppBundle:OAuth\Client')
                ->find($appId);

            if($client && ($user = $this->getUser()) && $user instanceof User) {
                $user->removeAuthorizedApplication($client);
                $this->getDoctrine()->getManager()->beginTransaction();
                $this->getDoctrine()->getRepository('AppBundle:User')->update($user);
                $this->getDoctrine()->getRepository('AppBundle:OAuth\\RefreshToken')
                        ->createQueryBuilder('t')
                        ->delete()
                        ->where('t.client = :client AND t.user = :user')
                        ->setParameter('client', $client)
                        ->setParameter('user', $user)
                        ->getQuery()
                        ->execute();
                $this->getDoctrine()->getRepository('AppBundle:OAuth\\AccessToken')
                        ->createQueryBuilder('t')
                        ->delete()
                        ->where('t.client = :client AND t.user = :user')
                        ->setParameter('client', $client)
                        ->setParameter('user', $user)
                        ->getQuery()
                        ->execute();
                $this->getDoctrine()->getManager()->commit();
                $this->get('braincrafted_bootstrap.flash')->success('Authorized application has been removed');
{'fraction_non_alphanumeric': 0.14018275016714954, 'fraction_numerical': 0.0, 'mean_word_length': 2.285505124450952, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 73, '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': '811845', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1129, 'n_words': 203}