<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, Nooku\Component\Users;

/**
 * Resettable Controller Behavior
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Component\Users
 */
class UsersControllerBehaviorResettable extends Users\ControllerBehaviorResettable
{
    protected function _beforeRead(Library\ControllerContextInterface $context)
    {
        $result = true;

        // Push the token to the view.
        if ($token = $context->request->query->get('token', $this->_filter))
        {
            $user = $this->getModel()->getRow();

            // Only passwords from enabled users can be reset.
            if (!$user->enabled)
            {
                $url = $this->getObject('application.pages')->getHome()->getLink();
                $this->getObject('application')->getRouter()->build($url);
                $context->response->setRedirect($url,
                    $this->getObject('translator')->translate('The user account you are trying to reset the password for is not enabled'), 'error');

                if ($user->activation)
                {
                    $context->response->addMessage($this->getObject('translator')->translate('Please activate your account before resetting your password'),
                        'notice');
                }

                $result = false;
            }
            else
            {
                $this->getView()->token = $token;
            }
        }

        return $result;
    }

    protected function _beforeReset(Library\ControllerContextInterface $context)
    {
        $result = true;

        if (!parent::_beforeReset($context))
        {
            $url = $this->getObject('application.pages')->getHome()->getLink();
            $this->getObject('application')->getRouter()->build($url);

            $context->response->setRedirect($url, $this->getObject('translator')->translate('Invalid request'), 'error');
            $result = false;
        }

        return $result;
    }

    protected function _beforeToken(Library\ControllerContextInterface $context)
    {
        $result = true;

        if (!parent::_beforeToken($context))
        {
            $url = $context->request->getReferrer();
            $context->response->setRedirect($url, $this->getObject('translator')->translate('Invalid request'), 'error');
            $result = false;
        }

        return $result;
    }

    protected function _afterToken(Library\ControllerContextInterface $context)
    {
        if ($context->result)
        {
            $page = $this->getObject('application.pages')->find(array(
                'component' => 'users',
                'published' => 1,
                'access'    => 0,
                'link'      => array(array('view' => 'user'))));

            if ($page)
            {
                $token = $context->token;
                $row   = $context->row;

                $url                  = $page->getLink();
                $url->query['layout'] = 'password';
                $url->query['token']  = $token;
                $url->query['uuid']   = $row->uuid;

                // TODO: This URL needs to be routed using the site app router.
                $this->getObject('application')->getRouter()->build($url);

                $url = $context->request->getUrl()
                                        ->toString(Library\HttpUrl::SCHEME | Library\HttpUrl::HOST | Library\HttpUrl::PORT) . $url;

                $site_name = \JFactory::getConfig()->getValue('sitename');

                $subject = $this->getObject('translator')->translate('{site} password reset', array('site' => $site_name));
                // TODO Fix when language package is re-factored.
                //$message    = \JText::sprintf('PASSWORD_RESET_CONFIRMATION_EMAIL_TEXT', $site_name, $url);
                $message = $url;

                if ($row->notify(array('subject' => $subject, 'message' => $message)))
                {
                    $message = array(
                        'text' => $this->getObject('translator')->translate('A confirmation E-mail for resetting your password has been sent to the address you have provided'),
                        'type' => 'success');
                }
                else
                {
                    $message = array(
                        'text' => $this->getObject('translator')->translate('The confirmation E-mail for resetting your password could not be sent'),
                        'type' => 'notice');
                }

                $url = $this->getObject('application.pages')->getHome()->getLink();
                $this->getObject('application')->getRouter()->build($url);

                $context->response->setRedirect($url, $message['text'], $message['type']);
            }
            else
            {
                $context->response->addMessage('Unable to get a password reset URL', 'error');
            }
        }
    }

    protected function _afterReset(Library\ControllerContextInterface $context)
    {
        if ($context->result)
        {
            $message = array('text' => $this->getObject('translator')->translate('Your password has been reset'), 'type' => 'success');
            $url     = $this->getObject('application.pages')->getHome()->getLink();
            $this->getObject('application')->getRouter()->build($url);

        }
        else
        {
            $message = array('text' => $context->error, 'type' => 'error');
            $url     = $context->request->getReferrer();
        }

        $context->response->setRedirect($url, $message['text'], $message['type']);
    }
}<commit_msg>re #302 re #352 Updated translate calls.<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, Nooku\Component\Users;

/**
 * Resettable Controller Behavior
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Component\Users
 */
class UsersControllerBehaviorResettable extends Users\ControllerBehaviorResettable
{
    protected function _beforeRead(Library\ControllerContextInterface $context)
    {
        $result = true;

        // Push the token to the view.
        if ($token = $context->request->query->get('token', $this->_filter))
        {
            $user = $this->getModel()->getRow();

            // Only passwords from enabled users can be reset.
            if (!$user->enabled)
            {
                $url = $this->getObject('application.pages')->getHome()->getLink();
                $this->getObject('application')->getRouter()->build($url);
                $context->response->setRedirect($url,
                    $this->getObject('translator')->translate('The user account you are trying to reset the password for is not enabled'), 'error');

                if ($user->activation)
                {
                    $context->response->addMessage($this->getObject('translator')->translate('Please activate your account before resetting your password'),
                        'notice');
                }

                $result = false;
            }
            else
            {
                $this->getView()->token = $token;
            }
        }

        return $result;
    }

    protected function _beforeReset(Library\ControllerContextInterface $context)
    {
        $result = true;

        if (!parent::_beforeReset($context))
        {
            $url = $this->getObject('application.pages')->getHome()->getLink();
            $this->getObject('application')->getRouter()->build($url);

            $context->response->setRedirect($url, $this->getObject('translator')->translate('Invalid request'), 'error');
            $result = false;
        }

        return $result;
    }

    protected function _beforeToken(Library\ControllerContextInterface $context)
    {
        $result = true;

        if (!parent::_beforeToken($context))
        {
            $url = $context->request->getReferrer();
            $context->response->setRedirect($url, $this->getObject('translator')->translate('Invalid request'), 'error');
            $result = false;
        }

        return $result;
    }

    protected function _afterToken(Library\ControllerContextInterface $context)
    {
        if ($context->result)
        {
            $page = $this->getObject('application.pages')->find(array(
                'component' => 'users',
                'published' => 1,
                'access'    => 0,
                'link'      => array(array('view' => 'user'))));

            $translator = $this->getObject('translator');

            if ($page)
            {
                $token = $context->token;
                $row   = $context->row;

                $url                  = $page->getLink();
                $url->query['layout'] = 'password';
                $url->query['token']  = $token;
                $url->query['uuid']   = $row->uuid;

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

                $url = $context->request->getUrl()
                                        ->toString(Library\HttpUrl::SCHEME | Library\HttpUrl::HOST | Library\HttpUrl::PORT) . $url;

                $subject = $translator->translate('Reset your password');
                $message = $translator->translate('Password reset instructions E-mail',
                    array('name' => $row->name, 'url' => $url));

                if ($row->notify(array('subject' => $subject, 'message' => $message)))
                {
                    $message = array(
                        'text' => $this->getObject('translator')->translate('A confirmation E-mail for resetting your password has been sent to the address you have provided'),
                        'type' => 'success');
                }
                else
                {
                    $message = array(
                        'text' => $this->getObject('translator')->translate('The confirmation E-mail for resetting your password could not be sent'),
                        'type' => 'notice');
                }

                $url = $this->getObject('application.pages')->getHome()->getLink();
                $this->getObject('application')->getRouter()->build($url);

                $context->response->setRedirect($url, $message['text'], $message['type']);
            }
            else
            {
                $context->response->addMessage($translator->translate('Unable to get a password reset URL'), 'error');
            }
        }
    }

    protected function _afterReset(Library\ControllerContextInterface $context)
    {
        if ($context->result)
        {
            $message = array('text' => $this->getObject('translator')->translate('Your password has been reset'), 'type' => 'success');
            $url     = $this->getObject('application.pages')->getHome()->getLink();
            $this->getObject('application')->getRouter()->build($url);

        }
        else
        {
            $message = array('text' => $context->error, 'type' => 'error');
            $url     = $context->request->getReferrer();
        }

        $context->response->setRedirect($url, $message['text'], $message['type']);
    }
}
{'fraction_non_alphanumeric': 0.15423138952550716, 'fraction_numerical': 0.0023767082590612004, 'mean_word_length': 1.9026853904902685, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 222, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2653593', 'n_tokens_mistral': 3098, 'n_tokens_neox': 2926, 'n_words': 588}