Example #1
0
 /**
  * beforeSave method
  *
  * @param mixed $Model
  * @return bool true (always)
  * @access public
  */
 function beforeSave(&$Model)
 {
     if (!$Model->id) {
         App::import('Component', 'RequestHandler');
         if (!isset($Model->data[$Model->alias]['ip'])) {
             $Model->data[$Model->alias]['ip'] = ip2long(RequestHandlerComponent::getClientIp());
         }
         $Model->data[$Model->alias]['junk_score'] = $this->score($Model, $Model->data);
         $log = $this->suspectLog($Model);
         $matches = $log['matchingRules'];
         $string = array();
         foreach ($matches as $rule => $score) {
             $string[] = $rule . ':' . $score;
         }
         $string = implode($string, ';');
         $Model->data[$Model->alias]['rule_matches'] = $string;
         $this->_addToWhitelist($Model, array('ip', 'junk_score', 'rule_matches'));
         if ($this->settings[$Model->alias]['autoStatus']) {
             $this->_addToWhitelist($Model, array('status'));
             $score = $this->score($Model, $Model->data);
             if ($score >= $this->settings[$Model->alias]['scoreSpam']) {
                 $Model->data[$Model->alias]['status'] = $this->settings[$Model->alias]['statusSpam'];
             } elseif ($score >= $this->settings[$Model->alias]['scoreSuspect']) {
                 $Model->data[$Model->alias]['status'] = $this->settings[$Model->alias]['statusSuspect'];
             } else {
                 $Model->data[$Model->alias]['status'] = $this->settings[$Model->alias]['statusHam'];
             }
         }
         $Model->data[$Model->alias]['junk_score'] = (int) $Model->data[$Model->alias]['junk_score'];
     }
     return true;
 }
Example #2
0
 /**
  * setUser method
  *
  * There's no need to call this method explicitly unless for whatever reason the current user's data
  * Isn't what you want to use, or it isn't where it's set to look ($_SESSION['Auth']['User']). You
  * might call this method during a shell to set the user id to an admin (for example)
  *
  * If called with data, it will set the current user data.
  * If called with true, it will reset the current user data (to whatever's in the session)
  * If called with no data, it will read from the session (if set) or use a fallback of userid = 0
  *
  * Also sets the ip to the current request if it isn't in the passed data array.
  *
  * @param mixed $Model
  * @param array $data array()
  * @return array current user data
  * @access public
  */
 function setUser(&$Model, $data = array())
 {
     if (!$data) {
         if ($this->_currentUser) {
             return $this->_currentUser;
         }
         if (isset($_SESSION['Auth']['User'])) {
             $data = $_SESSION['Auth']['User'];
         } else {
             $data['id'] = 0;
         }
         if (empty($data['ip'])) {
             App::import('Component', 'RequestHandler');
             $data['ip'] = ip2long(str_replace('::ffff:', '', RequestHandlerComponent::getClientIp()));
         }
     } elseif ($data === true) {
         $this->_currentUser = array();
         return $this->setUser($Model);
     }
     $this->_currentUser = $data;
     return $this->_currentUser;
 }