<commit_before><?php

namespace Bolt\Extension\Bolt\Members\Controller;

use Bolt\Asset\File\JavaScript;
use Bolt\Asset\File\Stylesheet;
use Bolt\Controller\Zone;
use Bolt\Extension\Bolt\Members\Config\Config;
use Bolt\Extension\Bolt\Members\MembersExtension;
use Bolt\Extension\Bolt\Members\Storage;
use Carbon\Carbon;
use Ramsey\Uuid\Uuid;
use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * Backend controller.
 *
 * Copyright (C) 2014-2016 <NAME>
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2014-2016, <NAME>
 * @license   https://opensource.org/licenses/MIT MIT
 */
class Backend implements ControllerProviderInterface
{
    /** @var Config */
    private $config;

    /**
     * Constructor.
     *
     * @param Config $config
     */
    public function __construct(Config $config)
    {
        $this->config = $config;
    }

    /**
     * {@inheritdoc}
     */
    public function connect(Application $app)
    {
        /** @var $ctr ControllerCollection */
        $ctr = $app['controllers_factory'];
        $ctr->value(Zone::KEY, Zone::BACKEND);

        $ctr->match('/extend/members', [$this, 'admin'])
            ->bind('membersAdmin')
            ->method('GET')
        ;

        $ctr->match('/extend/members/add', [$this, 'userAdd'])
            ->bind('membersAdminUserAdd')
            ->method('GET|POST')
        ;

        $ctr->match('/extend/members/action/userDelete', [$this, 'userDelete'])
            ->bind('membersAdminUserDel')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/userEnable', [$this, 'userEnable'])
            ->bind('membersAdminUserEnable')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/userDisable', [$this, 'userDisable'])
            ->bind('membersAdminUserDisable')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/roleAdd', [$this, 'roleAdd'])
            ->bind('membersAdminUserRoleAdd')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/roleDel', [$this, 'roleDel'])
            ->bind('membersAdminUserRoleDel')
            ->method('POST')
        ;

        $ctr->match('/extend/members/edit/{guid}', [$this, 'userEdit'])
            ->assert('guid', '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$')
            ->bind('membersAdminUserEdit')
            ->method('GET|POST')
        ;

        $ctr->before([$this, 'before']);

        return $ctr;
    }

    /**
     * Controller before render
     *
     * @param Request     $request
     * @param Application $app
     *
     * @return RedirectResponse|null
     */
    public function before(Request $request, Application $app)
    {
        $user    = $app['users']->getCurrentUser();
        $userid  = $user['id'];

        foreach ($this->config->getRolesAdmin() as $role) {
            if ($app['users']->hasRole($userid, $role)) {
                if (!$request->isXmlHttpRequest()) {
                    $this->addWebAssets($app);
                }

                return null;
            }
        }

        /** @var UrlGeneratorInterface $generator */
        $generator = $app['url_generator'];

        return new RedirectResponse($generator->generate('dashboard'), Response::HTTP_SEE_OTHER);
    }

    /**
     * Inject web assets for our route.
     *
     * @param Application $app
     */
    private function addWebAssets(Application $app)
    {
        /** @var MembersExtension $extension */
        $extension = $app['extensions']->get('Bolt/Members');
        $dir = $extension->getRelativeUrl();
        $saCss = (new Stylesheet($dir . 'css/sweetalert.css'))->setZone(Zone::BACKEND)->setLate(false);
        $saJs = (new JavaScript($dir . 'js/sweetalert.min.js'))->setZone(Zone::BACKEND)->setPriority(10)->setLate(true);
        $mCss = (new Stylesheet($dir . 'css/members-admin.css'))->setZone(Zone::BACKEND)->setLate(false);
        $mJs = (new JavaScript($dir . 'js/members-admin.js'))->setZone(Zone::BACKEND)->setPriority(20)->setLate(true);

        $app['asset.queue.file']->add($saCss);
        $app['asset.queue.file']->add($saJs);
        $app['asset.queue.file']->add($mCss);
        $app['asset.queue.file']->add($mJs);
    }

    /**
     * The main admin page
     *
     * @param Application $app
     * @param Request     $request
     *
     * @return Response
     */
    public function admin(Application $app, Request $request)<commit_msg>Update asset path handling<commit_after><?php

namespace Bolt\Extension\Bolt\Members\Controller;

use Bolt\Asset\File\JavaScript;
use Bolt\Asset\File\Stylesheet;
use Bolt\Controller\Zone;
use Bolt\Extension\Bolt\Members\Config\Config;
use Bolt\Extension\Bolt\Members\MembersExtension;
use Bolt\Extension\Bolt\Members\Storage;
use Carbon\Carbon;
use Ramsey\Uuid\Uuid;
use Silex\Application;
use Silex\ControllerCollection;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
 * Backend controller.
 *
 * Copyright (C) 2014-2016 <NAME>
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2014-2016, <NAME>
 * @license   https://opensource.org/licenses/MIT MIT
 */
class Backend implements ControllerProviderInterface
{
    /** @var Config */
    private $config;

    /**
     * Constructor.
     *
     * @param Config $config
     */
    public function __construct(Config $config)
    {
        $this->config = $config;
    }

    /**
     * {@inheritdoc}
     */
    public function connect(Application $app)
    {
        /** @var $ctr ControllerCollection */
        $ctr = $app['controllers_factory'];
        $ctr->value(Zone::KEY, Zone::BACKEND);

        $ctr->match('/extend/members', [$this, 'admin'])
            ->bind('membersAdmin')
            ->method('GET')
        ;

        $ctr->match('/extend/members/add', [$this, 'userAdd'])
            ->bind('membersAdminUserAdd')
            ->method('GET|POST')
        ;

        $ctr->match('/extend/members/action/userDelete', [$this, 'userDelete'])
            ->bind('membersAdminUserDel')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/userEnable', [$this, 'userEnable'])
            ->bind('membersAdminUserEnable')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/userDisable', [$this, 'userDisable'])
            ->bind('membersAdminUserDisable')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/roleAdd', [$this, 'roleAdd'])
            ->bind('membersAdminUserRoleAdd')
            ->method('POST')
        ;

        $ctr->match('/extend/members/action/roleDel', [$this, 'roleDel'])
            ->bind('membersAdminUserRoleDel')
            ->method('POST')
        ;

        $ctr->match('/extend/members/edit/{guid}', [$this, 'userEdit'])
            ->assert('guid', '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$')
            ->bind('membersAdminUserEdit')
            ->method('GET|POST')
        ;

        $ctr->before([$this, 'before']);

        return $ctr;
    }

    /**
     * Controller before render
     *
     * @param Request     $request
     * @param Application $app
     *
     * @return RedirectResponse|null
     */
    public function before(Request $request, Application $app)
    {
        $user    = $app['users']->getCurrentUser();
        $userid  = $user['id'];

        foreach ($this->config->getRolesAdmin() as $role) {
            if ($app['users']->hasRole($userid, $role)) {
                if (!$request->isXmlHttpRequest()) {
                    $this->addWebAssets($app);
                }

                return null;
            }
        }

        /** @var UrlGeneratorInterface $generator */
        $generator = $app['url_generator'];

        return new RedirectResponse($generator->generate('dashboard'), Response::HTTP_SEE_OTHER);
    }

    /**
     * Inject web assets for our route.
     *
     * @param Application $app
     */
    private function addWebAssets(Application $app)
    {
        /** @var MembersExtension $extension */
        $extension = $app['extensions']->get('Bolt/Members');
        $dir = $extension->getWebDirectory()->getPath();
        $saCss = (new Stylesheet('/' . $dir . '/css/sweetalert.css'))->setZone(Zone::BACKEND)->setLate(false);
        $saJs = (new JavaScript('/' . $dir . '/js/sweetalert.min.js'))->setZone(Zone::BACKEND)->setPriority(10)->setLate(true);
        $mCss = (new Stylesheet('/' . $dir . '/css/members-admin.css'))->setZone(Zone::BACKEND)->setLate(false);
        $mJs = (new JavaScript('/' . $dir . '/js/members-admin.js'))->setZone(Zone::BACKEND)->setPriority(20)->setLate(true);

        $app['asset.queue.file']->add($saCss);
        $app['asset.queue.file']->add($saJs);
        $app['asset.queue.file']->add($mCss);
        $app['asset.queue.file']->add($mJs);
    }

    /**
     * The main admin page
     *
     * @param Application $app
     * @param Request     $request
     *
     * @return Response
     */
    public function admin(Application $app, Request $request)
{'fraction_non_alphanumeric': 0.17459498503766382, 'fraction_numerical': 0.008048704984005778, 'mean_word_length': 2.4926126126126125, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 116, 'https://': 2, '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': '3798556', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2927, 'n_words': 462}