<commit_before><?php
/**
 * Belgian Police Web Platform - Zendesk Component
 *
 * @copyright	Copyright (C) 2012 - 2013 Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		https://github.com/belgianpolice/internet-platform
 */

use Nooku\Library;

class ZendeskControllerZendesk extends Library\ControllerView
{
    public function _actionRender(Library\CommandContext $context)
    {
        $user           = $this->getUser();

        if($user->getRole() < 24) {
            $url = clone($context->request->getUrl());
            $url->query['option'] = 'com_dashboard';

            $this->getObject('application')->getRouter()->build($url);

            return $this->getObject('component')->redirect($url);
        }

        require_once(JPATH_VENDOR . '/firebase/php-jwt/Firebase/PHP-JWT/Authentication/JWT.php');

        $key       = "<KEY>";
        $now       = time();

        $token = array(
            "jti"   => md5($now . rand()),
            "iat"   => $now,
            "name"  => $user->getName(),
            "email" => $user->getEmail()
        );

        $jwt = JWT::encode($token, $key);

        $url = 'https://police.zendesk.com/access/jwt?jwt=' . $jwt;

        return $this->getObject('component')->redirect($url);
    }
}<commit_msg>re #534 - Read Zendesk key from configuration file<commit_after><?php
/**
 * Belgian Police Web Platform - Zendesk Component
 *
 * @copyright	Copyright (C) 2012 - 2013 Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		https://github.com/belgianpolice/internet-platform
 */

use Nooku\Library;

class ZendeskControllerZendesk extends Library\ControllerView
{
    public function _actionRender(Library\CommandContext $context)
    {
        $application    = $this->getObject('application');
        $user           = $this->getUser();

        if($user->getRole() < 24)
        {
            $url = clone($context->request->getUrl());
            $url->query['option'] = 'com_dashboard';

            $this->getObject('application')->getRouter()->build($url);

            return $this->getObject('component')->redirect($url);
        }

        require_once(JPATH_VENDOR . '/firebase/php-jwt/Firebase/PHP-JWT/Authentication/JWT.php');

        $key       = $application->getCfg('api_zendesk');
        $now       = time();

        $token = array(
            "jti"   => md5($now . rand()),
            "iat"   => $now,
            "name"  => $user->getName(),
            "email" => $user->getEmail()
        );

        $jwt = JWT::encode($token, $key);

        $url = 'https://police.zendesk.com/access/jwt?jwt=' . $jwt;

        return $this->getObject('component')->redirect($url);
    }
}
{'fraction_non_alphanumeric': 0.17543227665706052, 'fraction_numerical': 0.009726224783861672, 'mean_word_length': 2.353864734299517, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 44, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '7247055', 'n_tokens_mistral': 905, 'n_tokens_neox': 854, 'n_words': 143}