<commit_before><?php
/*
 * This file is part of the CampaignChain package.
 *
 * (c) CampaignChain, Inc. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CampaignChain\Security\Authentication\Client\OAuthBundle\Controller;

use CampaignChain\CoreBundle\CampaignChainCoreBundle,
    CampaignChain\CoreBundle\Entity\Channel,
    CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Application,
    CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Profile,
    CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Token;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
    Symfony\Component\HttpFoundation\Session\Session,
    Symfony\Component\HttpFoundation\Request;

class OAuthController extends Controller
{
//    protected $channel;
//
//    protected $profile;
//
//    protected $token;
//
//    const STATUS_NEW_PROFILE = 'New profile and token';
//    const STATUS_NEW_TOKEN = 'New token and new scope';
//    const STATUS_NEW_SCOPE = 'Same token, but its scope updated';
//    const STATUS_SAME_SCOPE = 'Scope is the same';
//    const STATUS_NO_CHANGE = false;
//
//    private $status = self::STATUS_NO_CHANGE;
//
//    public function setChannel(Channel $channel){
//        $this->channel = $channel;
//    }
//
//    public function getChannel(){
//        return $this->channel;
//    }
//
//    public function setProfile(Profile $profile){
//        $this->profile = $profile;
//    }
//
//    public function getProfile(){
//        if(!$this->profile){
//            $repository = $this->getDoctrine()->getRepository('CampaignChainSecurityAuthenticationClientOAuthBundle:Profile');
//            $this->profile = $repository->findOneByChannel($this->channel);
//        }
//        return $this->profile;
//    }
//
//    public function setToken(Token $token){
//        $this->token = $token;
//    }

    public function newAction(Request $request)
    {
        $application = new Application();

        $form = $this->createFormBuilder($application)
            ->add('key', 'text', array('label' => 'App Key'))
            ->add('secret', 'text', array('label' => 'App Secret'))
            ->getForm();

        $form->handleRequest($request);

        if ($form->isValid()) {
            $application->setResourceOwner($request->query->get('resource_owner'));

            // perform some action, such as saving the task to the database
            $repository = $this->getDoctrine()->getManager();
            $repository->persist($application);
            $repository->flush();

            return $this->redirect($request->query->get('redirect'));
        }

        return $this->render(
            'CampaignChainCoreBundle:Base:new.html.twig',<commit_msg>refactor and fix code style<commit_after><?php
/*
 * This file is part of the CampaignChain package.
 *
 * (c) CampaignChain, Inc. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CampaignChain\Security\Authentication\Client\OAuthBundle\Controller;

use CampaignChain\CoreBundle\CampaignChainCoreBundle,
    CampaignChain\CoreBundle\Entity\Channel,
    CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Application,
    CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Profile,
    CampaignChain\Security\Authentication\Client\OAuthBundle\Entity\Token;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
    Symfony\Component\HttpFoundation\Session\Session,
    Symfony\Component\HttpFoundation\Request;

class OAuthController extends Controller
{
//    protected $channel;
//
//    protected $profile;
//
//    protected $token;
//
//    const STATUS_NEW_PROFILE = 'New profile and token';
//    const STATUS_NEW_TOKEN = 'New token and new scope';
//    const STATUS_NEW_SCOPE = 'Same token, but its scope updated';
//    const STATUS_SAME_SCOPE = 'Scope is the same';
//    const STATUS_NO_CHANGE = false;
//
//    private $status = self::STATUS_NO_CHANGE;
//
//    public function setChannel(Channel $channel){
//        $this->channel = $channel;
//    }
//
//    public function getChannel(){
//        return $this->channel;
//    }
//
//    public function setProfile(Profile $profile){
//        $this->profile = $profile;
//    }
//
//    public function getProfile(){
//        if(!$this->profile){
//            $repository = $this->getDoctrine()->getRepository('CampaignChainSecurityAuthenticationClientOAuthBundle:Profile');
//            $this->profile = $repository->findOneByChannel($this->channel);
//        }
//        return $this->profile;
//    }
//
//    public function setToken(Token $token){
//        $this->token = $token;
//    }

    public function newAction(Request $request)
    {
        $application = new Application();

        $form = $this->createFormBuilder($application)
            ->add('key', 'text', array('label' => 'App Key'))
            ->add('secret', 'text', array('label' => 'App Secret'))
            ->getForm();

        $form->handleRequest($request);

        if ($form->isValid()) {
            $application->setResourceOwner($request->query->get('resource_owner'));

            // perform some action, such as saving the task to the database
            $em = $this->getDoctrine()->getManager();
            $em->persist($application);
            $em->flush();

            return $this->redirect($request->query->get('redirect'));
        }

        return $this->render(
            'CampaignChainCoreBundle:Base:new.html.twig',
{'fraction_non_alphanumeric': 0.1434108527131783, 'fraction_numerical': 0.0, 'mean_word_length': 2.875085324232082, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 67, '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': '4307175', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1539, 'n_words': 331}