checkUser() public static method

Add ban data to all Get requests.
Since: 2.0.18
public static checkUser ( $User, Gdn_Validation $Validation = null, boolean $UpdateBlocks = false, &$BansFound = null ) : boolean
$Validation Gdn_Validation
$UpdateBlocks boolean
return boolean Whether user is banned.
コード例 #1
0
ファイル: class.usermodel.php プロジェクト: vanilla/vanilla
 /**
  * Synchronizes the user based on a given UserKey.
  *
  * @param string $UserKey A string that uniquely identifies this user.
  * @param array $Data Information to put in the user table.
  * @return int The ID of the user.
  */
 public function synchronize($UserKey, $Data)
 {
     $UserID = 0;
     $Attributes = val('Attributes', $Data);
     if (is_string($Attributes)) {
         $Attributes = dbdecode($Attributes);
     }
     if (!is_array($Attributes)) {
         $Attributes = [];
     }
     // If the user didnt log in, they won't have a UserID yet. That means they want a new
     // account. So create one for them.
     if (!isset($Data['UserID']) || $Data['UserID'] <= 0) {
         // Prepare the user data.
         $UserData = [];
         $UserData['Name'] = $Data['Name'];
         $UserData['Password'] = randomString(16);
         $UserData['Email'] = val('Email', $Data, '*****@*****.**');
         $UserData['Gender'] = strtolower(substr(val('Gender', $Data, 'u'), 0, 1));
         $UserData['HourOffset'] = val('HourOffset', $Data, 0);
         $UserData['DateOfBirth'] = val('DateOfBirth', $Data, '');
         $UserData['CountNotifications'] = 0;
         $UserData['Attributes'] = $Attributes;
         $UserData['InsertIPAddress'] = ipEncode(Gdn::request()->ipAddress());
         if ($UserData['DateOfBirth'] == '') {
             $UserData['DateOfBirth'] = '1975-09-16';
         }
         // Make sure there isn't another user with this username.
         if ($this->validateUniqueFields($UserData['Name'], $UserData['Email'])) {
             if (!BanModel::checkUser($UserData, $this->Validation, true)) {
                 throw permissionException('Banned');
             }
             // Insert the new user.
             $this->addInsertFields($UserData);
             $UserID = $this->insertInternal($UserData);
         }
         if ($UserID > 0) {
             $NewUserRoleIDs = $this->newUserRoleIDs();
             // Save the roles.
             $Roles = val('Roles', $Data, false);
             if (empty($Roles)) {
                 $Roles = $NewUserRoleIDs;
             }
             $this->saveRoles($UserID, $Roles, false);
         }
     } else {
         $UserID = $Data['UserID'];
     }
     // Synchronize the transientkey from the external user data source if it is present (eg. WordPress' wpnonce).
     if (array_key_exists('TransientKey', $Attributes) && $Attributes['TransientKey'] != '' && $UserID > 0) {
         $this->setTransientKey($UserID, $Attributes['TransientKey']);
     }
     return $UserID;
 }
コード例 #2
0
ファイル: class.usermodel.php プロジェクト: dimassrio/vanilla
 /**
  * Register a new user.
  *
  * @param $FormPostValues
  * @param array $Options
  * @return bool|int|string
  * @throws Exception
  */
 public function register($FormPostValues, $Options = array())
 {
     $Valid = true;
     $FormPostValues['LastIPAddress'] = Gdn::request()->ipAddress();
     // Throw an error if the registering user has an active session
     //      if (Gdn::session()->isValid())
     //         $this->Validation->addValidationResult('Name', 'You are already registered.');
     // Check for banning first.
     $Valid = BanModel::checkUser($FormPostValues, null, true);
     if (!$Valid) {
         $this->Validation->addValidationResult('UserID', 'Sorry, permission denied.');
     }
     // Throw an event to allow plugins to block the registration.
     unset($this->EventArguments['User']);
     $this->EventArguments['User'] = $FormPostValues;
     $this->EventArguments['Valid'] =& $Valid;
     $this->fireEvent('BeforeRegister');
     if (!$Valid) {
         return false;
         // plugin blocked registration
     }
     if (array_key_exists('Gender', $FormPostValues)) {
         $FormPostValues['Gender'] = self::fixGender($FormPostValues['Gender']);
     }
     $Method = strtolower(val('Method', $Options, c('Garden.Registration.Method')));
     switch ($Method) {
         case 'captcha':
             $UserID = $this->insertForBasic($FormPostValues, val('CheckCaptcha', $Options, true), $Options);
             break;
         case 'approval':
             $UserID = $this->insertForApproval($FormPostValues, $Options);
             break;
         case 'invitation':
             $UserID = $this->insertForInvite($FormPostValues, $Options);
             break;
         case 'closed':
             $UserID = false;
             $this->Validation->addValidationResult('Registration', 'Registration is closed.');
             break;
         case 'basic':
         default:
             $UserID = $this->insertForBasic($FormPostValues, val('CheckCaptcha', $Options, false), $Options);
             break;
     }
     if ($UserID) {
         $this->EventArguments['UserID'] = $UserID;
         $this->fireEvent('AfterRegister');
     }
     return $UserID;
 }