<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;

/**
 * Resettable Controller Behavior
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Component\Users
 */
class UsersControllerBehaviorResettable extends Users\ControllerBehaviorResettable
{
    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',
                '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} account activation', 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)))
                {
                    $context->getResponse()->addMessage(JText::_('ERROR_SENDING_CONFIRMATION_MAIL'), 'notice');
                }
            }
            else
            {
                $context->response->addMessage('Unable to get a password reset URL', 'error');
            }
        }
    }
}<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;
use Nooku\Component\Users;

/**
 * Resettable Controller Behavior
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Component\Users
 */
class UsersControllerBehaviorResettable extends Users\ControllerBehaviorResettable
{
    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',
                '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;

                // TODO: This is a frontend URL and we can't get a frontend router. To be solved.
                $this->getObject('application')->getRouter()->build($url);

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

                $site = $this->getObject('application')->getCfg('sitename');

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

                if (!$row->notify(array('subject' => $subject, 'message' => $message)))
                {
                    $context->getResponse()->addMessage($translator->translate('Unable to send password reset E-mail'), 'notice');
                }
            }
            else
            {
                $context->response->addMessage($translator->translate('Unable to get a password reset URL'), 'error');
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.1530045154567558, 'fraction_numerical': 0.0045154567558179926, 'mean_word_length': 2.0010422094841065, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 93, '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': '4333550', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1537, 'n_words': 301}