<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
 */

namespace Nooku\Component\Users;

use Nooku\Library;

/**
 * Activatable Controller Behavior
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Nooku\Component\Users
 */
class ControllerBehaviorActivatable extends Library\ControllerBehaviorAbstract
{
    /**
     * Determines whether new created items need activation or not.
     *
     * @var mixed bool
     */
    protected $_enable;

    /**
     * @var string The filter to be used on activation tokens.
     */
    protected $_filter;

    public function __construct(Library\ObjectConfig $config)
    {
        parent::__construct($config);

        $this->_enable = $config->enable;
        $this->_filter = $config->filter;
    }

    protected function _initialize(Library\ObjectConfig $config)
    {
        $config->append(array(
            'enable' => true,
            'filter' => 'alnum'
        ));

        parent::_initialize($config);
    }

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

        $activation = $context->request->data->get('activation', $this->_filter);
        $row        = $this->getModel()->getRow();

        if ($activation !== $row->activation)
        {
            $result = false;
        }

        return $result;
    }

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

        $row = $this->getModel()->getRow();
        $row->setData(array('activation' => '', 'enabled' => 1));

        if (!$row->save()) {
            $result = false;
        }

        return $result;
    }

    protected function _beforeAdd(Library\ControllerContextInterface $context)
    {
        // Set activation on new records.
        if ($this->_enable)
        {
            $context->request->data->activation = $this->getObject('com:users.database.row.password')->getRandom(32);
            $context->request->data->enabled    = 0;
        }
    }
}<commit_msg>re #352 Renamed property to something more meaningful.<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
 */

namespace Nooku\Component\Users;

use Nooku\Library;

/**
 * Activatable Controller Behavior
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/arunasmazeika>
 * @package Nooku\Component\Users
 */
class ControllerBehaviorActivatable extends Library\ControllerBehaviorAbstract
{
    /**
     * Determines whether new created items will be forced for activation.
     *
     * @var mixed bool
     */
    protected $_force;

    /**
     * @var string The filter to be used on activation tokens.
     */
    protected $_filter;

    public function __construct(Library\ObjectConfig $config)
    {
        parent::__construct($config);

        $this->_force = $config->force;
        $this->_filter = $config->filter;
    }

    protected function _initialize(Library\ObjectConfig $config)
    {
        $config->append(array(
            'force' => true,
            'filter' => 'alnum'
        ));

        parent::_initialize($config);
    }

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

        $activation = $context->request->data->get('activation', $this->_filter);
        $row        = $this->getModel()->getRow();

        if ($activation !== $row->activation)
        {
            $result = false;
        }

        return $result;
    }

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

        $row = $this->getModel()->getRow();
        $row->setData(array('activation' => '', 'enabled' => 1));

        if (!$row->save()) {
            $result = false;
        }

        return $result;
    }

    protected function _beforeAdd(Library\ControllerContextInterface $context)
    {
        // Force activation on new records.
        if ($this->_force)
        {
            $context->request->data->activation = $this->getObject('com:users.database.row.password')->getRandom(32);
            $context->request->data->enabled    = 0;
        }
    }
}
{'fraction_non_alphanumeric': 0.13954477770687088, 'fraction_numerical': 0.006168900233992768, 'mean_word_length': 2.427113702623907, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 69, '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': '7481629', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1325, 'n_words': 280}