<commit_before><?php

/*
 * This file is part of the Savel Bundle for Symfony 2
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Mach\SavelBundle\Controller;

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Mach\SavelBundle\Snufkin\Snufkin as Snufkin;

/**
 * Controller that is used for connecting with a proper Snufkin and
 * to confirm the credentials and create/update the user.
 *
 * @package MachSavelBundle
 * @subpackage Controller
 * @author <NAME> <<EMAIL>>
 * @version 1.0
 */
class SnufkinController extends Controller
{
    /**
     * Action used for connecting with an OAuth service.
     *
     * @param string $service Service name parameter
     * @return \Symfony\Component\HttpFoundation\Response Response object
     */
    public function connectAction($service)
    {
        $snufkin_manager = $this->get('mach_savel.snufkin.manager');
        $snufkin = $snufkin_manager->getSnufkin($service);
        
        $request = $this->get('request');
        $referer = $request->server->get('HTTP_REFERER');
        $request->getSession()->set('mach_savel_referer', $referer);
        
        return $this->redirect($snufkin->connect());
    }
    
    /**
     * Action used for confirming credentials fetched with an OAuth service.
     *
     * @param string $service Service name parameter
     * @return \Symfony\Component\HttpFoundation\Response Response object
     */
    public function confirmAction($service)
    {
        $code = $this->get('request')->get('code');
        
        if (empty($code))
        {
            throw new \InvalidArgumentException("You have to provide \"code\" parameter.");
        }
        
        $snufkin_manager = $this->get('mach_savel.snufkin.manager');
        $snufkin = $snufkin_manager->getSnufkin($service);
        
        $token = $snufkin->confirm($code, 'http://symfony2.dev.tld.com/connect/Google/confirm');
        //$token = $snufkin->confirm($code);
        
        $user = $snufkin->callUserBridge($token);
        
        $authentication_token = new UsernamePasswordToken(<commit_msg>Fixed a bug in the controller.<commit_after><?php

/*
 * This file is part of the Savel Bundle for Symfony 2
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Mach\SavelBundle\Controller;

use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Mach\SavelBundle\Snufkin\Snufkin as Snufkin;

/**
 * Controller that is used for connecting with a proper Snufkin and
 * to confirm the credentials and create/update the user.
 *
 * @package MachSavelBundle
 * @subpackage Controller
 * @author <NAME> <<EMAIL>>
 * @version 1.0
 */
class SnufkinController extends Controller
{
    /**
     * Action used for connecting with an OAuth service.
     *
     * @param string $service Service name parameter
     * @return \Symfony\Component\HttpFoundation\Response Response object
     */
    public function connectAction($service)
    {
        $snufkin_manager = $this->get('mach_savel.snufkin.manager');
        $snufkin = $snufkin_manager->getSnufkin($service);
        
        $request = $this->get('request');
        $referer = $request->server->get('HTTP_REFERER');
        $request->getSession()->set('mach_savel_referer', $referer);
        
        return $this->redirect($snufkin->connect());
    }
    
    /**
     * Action used for confirming credentials fetched with an OAuth service.
     *
     * @param string $service Service name parameter
     * @return \Symfony\Component\HttpFoundation\Response Response object
     */
    public function confirmAction($service)
    {
        $code = $this->get('request')->get('code');
        
        if (empty($code))
        {
            throw new \InvalidArgumentException("You have to provide \"code\" parameter.");
        }
        
        $snufkin_manager = $this->get('mach_savel.snufkin.manager');
        $snufkin = $snufkin_manager->getSnufkin($service);
        
        $token = $snufkin->confirm($code);
        
        $user = $snufkin->callUserBridge($token);
        
        $authentication_token = new UsernamePasswordToken(
{'fraction_non_alphanumeric': 0.11971517578994215, 'fraction_numerical': 0.001557632398753894, 'mean_word_length': 2.936077057793345, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 46, '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': '949252', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1269, 'n_words': 317}