<commit_before><?php

namespace Bolt\Extension\Bolt\Members\Controller;

use Silex;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
use Bolt\Extension\Bolt\Members\Extension;
use Bolt\Extension\Bolt\Members\Members;
use Bolt\Extension\Bolt\Members\Validator\Constraints\ValidUsername;
use Bolt\Extension\Bolt\Members\Entity\Register;
use Bolt\Extension\Bolt\Members\Form\RegisterType;

/**
 *
 */
class MembersController implements ControllerProviderInterface
{
    /**
     * Extension config array
     *
     * @var array
     */
    private $config;

    /**
     * @var Members
     */
    private $members;

    /**
     *
     * @param Silex\Application $app
     * @return \Silex\ControllerCollection
     */
    public function connect(Silex\Application $app)
    {
        $this->config = $app['extensions.' . Extension::NAME]->config;
        $this->members = new Members($app);

        /**
         * @var $ctr \Silex\ControllerCollection
         */
        $ctr = $app['controllers_factory'];

        // New member
        $ctr->match('/register', array($this, 'register'))
            ->bind('register')
            ->method('GET|POST');

        // My profile
        $ctr->match('/profile', array($this, 'myprofile'))
            ->bind('myprofile')
            ->method('GET|POST');

        // Member profile
        $ctr->match('/profile/{id}', array($this, 'userprofile'))
            ->bind('userprofile')
            ->assert('id', '\d*')
            ->method('GET');

        return $ctr;
    }

    /**
     *
     * @param Silex\Application $app
     * @param Symfony\Component\HttpFoundation\Request $request
     * @return \Twig_Markup
     */
    public function register(Silex\Application $app, Request $request)
    {
        // Add assets to Twig path
        $this->addTwigPath($app);

        // Get redirect that is set for ClientLogin
        $redirect = $app['session']->get('pending');

        // Get session data we need from ClientLogin
        $clientlogin = $app['session']->get('clientlogin');

        // If there is no ClientLogin data in the session, they shouldn't be here
        if (empty($clientlogin)) {
            return new Response('No!', Response::HTTP_FORBIDDEN, array('content-type' => 'text/html'));
        }

        // Expand the JSON array
        $userdata = json_decode($clientlogin['providerdata'], true);
        $userdata['provider'] = $clientlogin['provider'];

        $register = new Register();
        $data = array(
            'csrf_protection' => $this->config['csrf'],
            'data' => array(
                'username'    => makeSlug($userdata['displayName'], 32),
                'displayname' => $userdata['displayName'],
                'email'       => $userdata['email']
            )
        );

        // Create new register form
        $form = $app['form.factory']->createBuilder(new RegisterType(), $register, $data)
                                    ->getForm();

        // Handle the form request data
        $form->handleRequest($request);

        // If we're in a POST, validate the form
        if ($request->getMethod() == 'POST') {
            if ($form->isValid()) {
                // Create new Member record and go back to where we came from
                if ($this->members->addMember($request->get('register'), $userdata)) {
                    // Clear any redirect that ClientLogin has pending
                    $app['session']->remove('pending');
                    $app['session']->remove('clientlogin');

                    // Redirect
                    if (empty($redirect)) {
                        simpleredirect($app['paths']['hosturl']);
                    } else {
                        $returnpage = str_replace($app['paths']['hosturl'], '', $redirect);
                        simpleredirect($returnpage);
                    }
                } else {
                    // Something is wrong here
                }
            }
        }

        $html = $app['render']->render(
            $this->config['templates']['register'], array(
                'form' => $form->createView(),
                'twigparent' => $this->config['templates']['parent']
        ));

        return new \Twig_Markup($html, 'UTF-8');
    }

    /**
     *
     * @param Silex\Application $app
     * @param Symfony\Component\HttpFoundation\Request $request
     * @return \Twig_Markup
     */
    public function myprofile(Silex\Application $app, Request $request)
    {
        // Add assets to Twig path
        $this->addTwigPath($app);

        $view = '';

        $html = $app['render']->render(
            $this->config['templates']['profile'], array(
                'form' => $view,
                'twigparent' => $this->config['templates']['parent']
        ));

        return new \Twig_Markup($html, 'UTF-8');
    }

    /**
     *
     * @param Silex\Application $app
     * @param Symfony\Component\HttpFoundation\Request $request<commit_msg>Start of logic for profile page<commit_after><?php

namespace Bolt\Extension\Bolt\Members\Controller;

use Silex;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
use Bolt\Extension\Bolt\Members\Extension;
use Bolt\Extension\Bolt\Members\Members;
use Bolt\Extension\Bolt\Members\Validator\Constraints\ValidUsername;
use Bolt\Extension\Bolt\Members\Entity\Register;
use Bolt\Extension\Bolt\Members\Form\RegisterType;

/**
 *
 */
class MembersController implements ControllerProviderInterface
{
    /**
     * Extension config array
     *
     * @var array
     */
    private $config;

    /**
     * @var Members
     */
    private $members;

    /**
     *
     * @param Silex\Application $app
     * @return \Silex\ControllerCollection
     */
    public function connect(Silex\Application $app)
    {
        $this->config = $app['extensions.' . Extension::NAME]->config;
        $this->members = new Members($app);

        /**
         * @var $ctr \Silex\ControllerCollection
         */
        $ctr = $app['controllers_factory'];

        // New member
        $ctr->match('/register', array($this, 'register'))
            ->bind('register')
            ->method('GET|POST');

        // My profile
        $ctr->match('/profile', array($this, 'myprofile'))
            ->bind('myprofile')
            ->method('GET|POST');

        // Member profile
        $ctr->match('/profile/{id}', array($this, 'userprofile'))
            ->bind('userprofile')
            ->assert('id', '\d*')
            ->method('GET');

        return $ctr;
    }

    /**
     *
     * @param Silex\Application $app
     * @param Symfony\Component\HttpFoundation\Request $request
     * @return \Twig_Markup
     */
    public function register(Silex\Application $app, Request $request)
    {
        // Add assets to Twig path
        $this->addTwigPath($app);

        // Get redirect that is set for ClientLogin
        $redirect = $app['session']->get('pending');

        // Get session data we need from ClientLogin
        $clientlogin = $app['session']->get('clientlogin');

        // If there is no ClientLogin data in the session, they shouldn't be here
        if (empty($clientlogin)) {
            return new Response('No!', Response::HTTP_FORBIDDEN, array('content-type' => 'text/html'));
        }

        // Expand the JSON array
        $userdata = json_decode($clientlogin['providerdata'], true);
        $userdata['provider'] = $clientlogin['provider'];

        // Create new register form
        $register = new Register();
        $data = array(
            'csrf_protection' => $this->config['csrf'],
            'data' => array(
                'username'    => makeSlug($userdata['displayName'], 32),
                'displayname' => $userdata['displayName'],
                'email'       => $userdata['email']
            )
        );

        $form = $app['form.factory']->createBuilder(new RegisterType(), $register, $data)
                                    ->getForm();

        // Handle the form request data
        $form->handleRequest($request);

        // If we're in a POST, validate the form
        if ($request->getMethod() == 'POST') {
            if ($form->isValid()) {
                // Create new Member record and go back to where we came from
                if ($this->members->addMember($request->get('register'), $userdata)) {
                    // Clear any redirect that ClientLogin has pending
                    $app['session']->remove('pending');
                    $app['session']->remove('clientlogin');

                    // Redirect
                    if (empty($redirect)) {
                        simpleredirect($app['paths']['hosturl']);
                    } else {
                        $returnpage = str_replace($app['paths']['hosturl'], '', $redirect);
                        simpleredirect($returnpage);
                    }
                } else {
                    // Something is wrong here
                }
            }
        }

        $html = $app['render']->render(
            $this->config['templates']['register'], array(
                'form' => $form->createView(),
                'twigparent' => $this->config['templates']['parent']
        ));

        return new \Twig_Markup($html, 'UTF-8');
    }

    /**
     *
     * @param Silex\Application $app
     * @param Symfony\Component\HttpFoundation\Request $request
     * @return \Twig_Markup
     */
    public function myprofile(Silex\Application $app, Request $request)
    {
        // Add assets to Twig path
        $this->addTwigPath($app);

        // Create new register form
        $profile = new Profile();
        $data = array(
            'csrf_protection' => $this->config['csrf'],
            'data' => array(
                'username'    => '',
                'displayname' => '',
                'email'       => '',
                'allowsave'   => true
            )
        );

        $form = $app['form.factory']->createBuilder(new ProfileType(), $profile, $data)
                                    ->getForm();

        $html = $app['render']->render(
            $this->config['templates']['profile'], array(
                'form' => $view,
                'twigparent' => $this->config['templates']['parent']
        ));

        return new \Twig_Markup($html, 'UTF-8');
    }

    /**
     *
     * @param Silex\Application $app
     * @param Symfony\Component\HttpFoundation\Request $request
{'fraction_non_alphanumeric': 0.14915222656977828, 'fraction_numerical': 0.0007452953232718465, 'mean_word_length': 1.887305002689618, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 102, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2998901', 'n_tokens_mistral': 2929, 'n_tokens_neox': 2825, 'n_words': 601}