saveUser() public method

Change ban data on a user (ban or unban them).
Since: 2.0.18
public saveUser ( array $User, boolean $BannedValue, array | false $Ban = false )
$User array
$BannedValue boolean Whether user is banned.
$Ban array | false An array representing the specific auto-ban.
Ejemplo n.º 1
0
 /**
  * Updates visit level information such as date last active and the user's ip address.
  *
  * @param int $UserID
  * @param string|int|float $ClientHour
  */
 public function updateVisit($UserID, $ClientHour = false)
 {
     $UserID = (int) $UserID;
     if (!$UserID) {
         throw new Exception('A valid User ID is required.');
     }
     $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY);
     $Fields = [];
     if (Gdn_Format::toTimestamp($User['DateLastActive']) < strtotime('5 minutes ago')) {
         // We only update the last active date once every 5 minutes to cut down on DB activity.
         $Fields['DateLastActive'] = Gdn_Format::toDateTime();
     }
     // Update session level information if necessary.
     if ($UserID == Gdn::session()->UserID) {
         $IP = Gdn::request()->ipAddress();
         $Fields['LastIPAddress'] = ipEncode($IP);
         $this->saveIP($UserID, $IP);
         if (Gdn::session()->newVisit()) {
             $Fields['CountVisits'] = val('CountVisits', $User, 0) + 1;
             $this->fireEvent('Visit');
         }
     }
     // Set the hour offset based on the client's clock.
     if (is_numeric($ClientHour) && $ClientHour >= 0 && $ClientHour < 24) {
         $HourOffset = $ClientHour - date('G', time());
         $Fields['HourOffset'] = $HourOffset;
     }
     // See if the fields have changed.
     $Set = [];
     foreach ($Fields as $Name => $Value) {
         if (val($Name, $User) != $Value) {
             $Set[$Name] = $Value;
         }
     }
     if (!empty($Set)) {
         $this->EventArguments['Fields'] =& $Set;
         $this->fireEvent('UpdateVisit');
         $this->setField($UserID, $Set);
     }
     if ($User['LastIPAddress'] != $Fields['LastIPAddress']) {
         $User = $this->getID($UserID, DATASET_TYPE_ARRAY);
         if (!BanModel::checkUser($User, null, true, $Bans)) {
             $BanModel = new BanModel();
             $Ban = array_pop($Bans);
             $BanModel->saveUser($User, true, $Ban);
             $BanModel->setCounts($Ban);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Updates visit level information such as date last active and the user's ip address.
  *
  * @param int $UserID
  * @param string|int|float $ClientHour
  */
 function updateVisit($UserID, $ClientHour = false)
 {
     $UserID = (int) $UserID;
     if (!$UserID) {
         throw new Exception('A valid User ID is required.');
     }
     $User = Gdn::userModel()->getID($UserID, DATASET_TYPE_ARRAY);
     $Fields = array();
     if (Gdn_Format::toTimestamp($User['DateLastActive']) < strtotime('5 minutes ago')) {
         // We only update the last active date once every 5 minutes to cut down on DB activity.
         $Fields['DateLastActive'] = Gdn_Format::toDateTime();
     }
     // Update session level information if necessary.
     if ($UserID == Gdn::session()->UserID) {
         $IP = Gdn::request()->ipAddress();
         $Fields['LastIPAddress'] = $IP;
         if (Gdn::session()->newVisit()) {
             $Fields['CountVisits'] = val('CountVisits', $User, 0) + 1;
             $this->fireEvent('Visit');
         }
     }
     // Generate the AllIPs field.
     $AllIPs = val('AllIPAddresses', $User, array());
     if (is_string($AllIPs)) {
         $AllIPs = explode(',', $AllIPs);
         setValue('AllIPAddresses', $User, $AllIPs);
     }
     if (!is_array($AllIPs)) {
         $AllIPs = array();
     }
     if ($IP = val('InsertIPAddress', $User)) {
         array_unshift($AllIPs, ForceIPv4($IP));
     }
     if ($IP = val('LastIPAddress', $User)) {
         array_unshift($AllIPs, $IP);
     }
     // This will be a unique list of IPs, most recently used first. array_unique keeps the first key found.
     $AllIPs = array_unique($AllIPs);
     $Fields['AllIPAddresses'] = $AllIPs;
     // Set the hour offset based on the client's clock.
     if (is_numeric($ClientHour) && $ClientHour >= 0 && $ClientHour < 24) {
         $HourOffset = $ClientHour - date('G', time());
         $Fields['HourOffset'] = $HourOffset;
     }
     // See if the fields have changed.
     $Set = array();
     foreach ($Fields as $Name => $Value) {
         if (val($Name, $User) != $Value) {
             $Set[$Name] = $Value;
         }
     }
     if (!empty($Set)) {
         $this->EventArguments['Fields'] =& $Set;
         $this->fireEvent('UpdateVisit');
         $this->setField($UserID, $Set);
     }
     if ($User['LastIPAddress'] != $Fields['LastIPAddress']) {
         $User = $this->getID($UserID, DATASET_TYPE_ARRAY);
         if (!BanModel::checkUser($User, null, true, $Bans)) {
             $BanModel = new BanModel();
             $Ban = array_pop($Bans);
             $BanModel->saveUser($User, true, $Ban);
             $BanModel->setCounts($Ban);
         }
     }
 }