Nooku Server is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

nooku-server

Commit 3339

User picture
  • Author: arunasmazeika
  • 2012-02-22 11:01 (about 2 years ago)

Spammed can now be passed an array for defining the checks to be executed.

re #186

Files Affected

 
33383339
40
    protected function _beforeControllerAdd(KCommandContext $context)
40
    protected function _beforeControllerAdd(KCommandContext $context)
41
    {
41
    {
42
        // Avoid spammed data from being used.
42
        // Avoid spammed data from being used.
43
        return (bool) !$this->spammed($context->data);
43
        return (bool) !$this->spammed(array('data' => $context->data));
44
    }
44
    }
45
 
45
 
46
    protected function _initialize(KConfig $config)
46
    protected function _initialize(KConfig $config)
...
 
...
 
71
    /**
71
    /**
72
     * Tells if the POST data within the current request is potentially spammed.
72
     * Tells if the POST data within the current request is potentially spammed.
73
     *
73
     *
 
 
74
     * @param
 
 
75
     *            array An optional configuration array.
74
     * @throws KControllerBehaviorException If a requested spam check is not
76
     * @throws KControllerBehaviorException If a requested spam check is not
75
     *         implemented.
77
     *         implemented.
76
     * @return boolean True if spam is suspected, false otherwise.
78
     * @return boolean True if spam is suspected, false otherwise.
77
     */
79
     */
78
    public function spammed(KConfig $data)
80
    public function spammed($config = array())
79
    {
81
    {
80
        if(!isset($this->_spammed)) {
82
        if(!isset($this->_spammed)) {
 
 
83
            $config = new KConfig($config);
 
 
84
            if(!$config->checks) {
 
 
85
                // Use behavior checks.
 
 
86
                $config->checks = $this->_checks;
 
 
87
            }
81
            // Initialize the spammed status as false.
88
            // Initialize the spammed status as false.
82
            $this->_spammed = false;
89
            $this->_spammed = false;
83
            foreach($this->_checks as $key => $val) {
90
            foreach($config->checks as $key => $val) {
84
                if(is_numeric($key)) {
91
                if(is_numeric($key)) {
85
                    $check = $val;
92
                    $check = $val;
86
                    $config = array();
93
                    $params = array();
87
                } else {
94
                } else {
88
                    $check = $key;
95
                    $check = $key;
89
                    $config = $val;
96
                    $params = $val;
90
                }
97
                }
91
                // Append data.
98
                // Append data (if any).
92
                $config['data'] = $data;
99
                $params['data'] = $config->data;
93
                $method = '_' . $check . 'Check';
100
                $method = '_' . $check . 'Check';
94
                if(!method_exists($this, $method)) {
101
                if(!method_exists($this, $method)) {
95
                    throw new KControllerBehaviorException('Unknown spam check.');
102
                    throw new KControllerBehaviorException('Unknown spam check.');
96
                }
103
                }
97
                if(!$this->$method($config)) {
104
                if(!$this->$method($params)) {
98
                    // Set current status as spammed.
105
                    // Set current status as spammed.
99
                    $this->_spammed = true;
106
                    $this->_spammed = true;
100
                    break;
107
                    break;
...
 
...
 
294
        }
301
        }
295
        return true;
302
        return true;
296
    }
303
    }
297
 
 
 
298
}
304
}
33383339
75
        if ($captcha_passed) {
75
        if ($captcha_passed) {
76
            // Force form/data as not spammed.
76
            // Force form/data as not spammed.
77
            $this->setSpammed(false);
77
            $this->setSpammed(false);
78
        } elseif ($this->spammed($context->data)) {
78
        } elseif ($this->spammed(array('data' => $context->data))) {
79
            // Temporarily store current user data.
79
            // Temporarily store current user data.
80
            KRequest::set('session.com.users.controller.user.data', $context->data->toArray());
80
            KRequest::set('session.com.users.controller.user.data', $context->data->toArray());
81
            // Re-direct to captcha view.
81
            // Re-direct to captcha view.