<commit_before><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2011 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

use Nooku\Library;
use Nooku\Component\Users;

/**
 * Session Controller
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Component\Users
 */
class UsersControllerSession extends Users\ControllerSession
{
    public function __construct(Library\ObjectConfig $config)
    {
        parent::__construct($config);

        //Authorize the user before adding
        $this->addCommandCallback('after.add'  , '_passwordRedirect');
    }

    protected function _initialize(Library\ObjectConfig $config)
    {
        $config->append(array(
            'behaviors' => array(
                'com:activities.controller.behavior.loggable' => array('title_column' => 'name')
            )
        ));

        parent::_initialize($config);
    }

    protected function _passwordRedirect(Library\ControllerContextInterface $context)
    {
        if ($context->result !== false)
        {
            $user     = $context->user;
            $password = $this->getObject('com:users.database.row.password')->set('id', $user->getEmail())->load();

            if ($password->expired())
            {
                $pages  = $this->getObject('application.pages');

                $page = $pages->find(array(
                    'component' => 'users',
                    'link'      => array(array('view' => 'user'))));

                if ($page)
                {
                    $url                  = $page->getLink();
                    $url->query['layout'] = 'password';
                    $url->query['id']     = $user->getId();

                    $this->getObject('application')->getRouter()->build($url);
                    $context->response->setRedirect($url, \JText::_('Your password has expired'), 'notice');
                }
            }
        }
    }

    protected function _actionAdd(Library\ControllerContextInterface $context)
    {
        $result = parent::_actionAdd($context);

        //Set the session data
        if($context->response->isSuccess())
        {
            $context->user->getSession()->site = $this->getObject('application')->getSite();
            $url = $this->getObject('application.pages')->getHome()->getLink();
            $this->getObject('application')->getRouter()->build($url);
            $context->response->setRedirect($url);
        }

        return $result;
    }

    protected function _actionDelete(Library\ControllerContextInterface $context)
    {
        $entity = parent::_actionDelete($context);

        //Redirect to caller
        $context->response->setRedirect($context->request->getReferrer());

        return $entity;<commit_msg>re #302 Use our own translator.<commit_after><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2011 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

use Nooku\Library;
use Nooku\Component\Users;

/**
 * Session Controller
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Component\Users
 */
class UsersControllerSession extends Users\ControllerSession
{
    public function __construct(Library\ObjectConfig $config)
    {
        parent::__construct($config);

        //Authorize the user before adding
        $this->addCommandCallback('after.add'  , '_passwordRedirect');
    }

    protected function _initialize(Library\ObjectConfig $config)
    {
        $config->append(array(
            'behaviors' => array(
                'com:activities.controller.behavior.loggable' => array('title_column' => 'name')
            )
        ));

        parent::_initialize($config);
    }

    protected function _passwordRedirect(Library\ControllerContextInterface $context)
    {
        if ($context->result !== false)
        {
            $user     = $context->user;
            $password = $this->getObject('com:users.database.row.password')->set('id', $user->getEmail())->load();

            if ($password->expired())
            {
                $pages  = $this->getObject('application.pages');

                $page = $pages->find(array(
                    'component' => 'users',
                    'link'      => array(array('view' => 'user'))));

                if ($page)
                {
                    $url                  = $page->getLink();
                    $url->query['layout'] = 'password';
                    $url->query['id']     = $user->getId();

                    $this->getObject('application')->getRouter()->build($url);
                    $context->response->setRedirect($url,
                        $this->getObject('translator')->translate('Your password has expired. Please set a new password'), 'notice');
                }
            }
        }
    }

    protected function _actionAdd(Library\ControllerContextInterface $context)
    {
        $result = parent::_actionAdd($context);

        //Set the session data
        if($context->response->isSuccess())
        {
            $context->user->getSession()->site = $this->getObject('application')->getSite();
            $url = $this->getObject('application.pages')->getHome()->getLink();
            $this->getObject('application')->getRouter()->build($url);
            $context->response->setRedirect($url);
        }

        return $result;
    }

    protected function _actionDelete(Library\ControllerContextInterface $context)
    {
        $entity = parent::_actionDelete($context);

        //Redirect to caller
        $context->response->setRedirect($context->request->getReferrer());

        return $entity;
{'fraction_non_alphanumeric': 0.1540634867874356, 'fraction_numerical': 0.0034901113511716804, 'mean_word_length': 2.194267515923567, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '3223243', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1586, 'n_words': 273}