<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/johanjanssens>
 * @package Component\Users
 */
class UsersControllerBehaviorResettable extends Users\ControllerBehaviorResettable
{
    protected function _beforeRead(Library\ControllerContextInterface $context)
    {
        // Push the token to the view.
        if ($token = $context->request->query->get('token', $this->_filter)) {
            $this->getView()->token = $token;
        }
    }

    protected function _afterToken(Library\ControllerContextInterface $context)
    {
        if (!$context->result)
        {
            $message = JText::_('ERROR_SENDING_CONFIRMATION_EMAIL');
            $type    = 'error';

            $url = $context->request->getReferrer();
        }
        else
        {
            $message = JText::_('CONFIRMATION_EMAIL_SUCCESS');
            $type    = 'success';

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

        $context->response->setRedirect($url, $message, $type);
    }

    protected function _afterReset(Library\ControllerContextInterface $context)
    {
        if ($context->result)
        {
            $message = JText::_('PASSWORD_RESET_SUCCESS');

            $url     = $this->getObject('application.pages')->getHome()->getLink();<commit_msg>re #352 Make sure that a password reset page is available before issuing a token. Send the reset url to the password owner mail.<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/johanjanssens>
 * @package Component\Users
 */
class UsersControllerBehaviorResettable extends Users\ControllerBehaviorResettable
{
    protected function _beforeRead(Library\ControllerContextInterface $context)
    {
        // Push the token to the view.
        if ($token = $context->request->query->get('token', $this->_filter)) {
            $this->getView()->token = $token;
        }
    }

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

        if (parent::_beforeToken($context))
        {
            $page = $this->getObject('application.pages')->find(array(
                'component' => 'users',
                'access'    => 0,
                'link'      => array(array('view' => 'user'))));

            if ($page)
            {
                $context->page = $page;
                $result = true;
            }
        }

        return $result;
    }

    protected function _afterToken(Library\ControllerContextInterface $context)
    {
        if ($context->result)
        {
            $page  = $context->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;

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

            $subject = \JText::sprintf('PASSWORD_RESET_CONFIRMATION_EMAIL_TITLE', $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 = JText::_('CONFIRMATION_EMAIL_SUCCESS');
                $type    = 'success';

                $url = $this->getObject('application.pages')->getHome()->getLink();
                $this->getObject('application')->getRouter()->build($url);
            }
            else
            {
                $message = JText::_('ERROR_SENDING_CONFIRMATION_EMAIL');
                $type    = 'error';

                $url = $context->request->getReferrer();
            }

            $context->response->setRedirect($url, $message, $type);
        }
    }

    protected function _afterReset(Library\ControllerContextInterface $context)
    {
        if ($context->result)
        {
            $message = JText::_('PASSWORD_RESET_SUCCESS');

            $url     = $this->getObject('application.pages')->getHome()->getLink();
{'fraction_non_alphanumeric': 0.14904482693398902, 'fraction_numerical': 0.004161149990542841, 'mean_word_length': 2.258163894023413, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404716', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1487, 'n_words': 269}