UserModel::validateUniqueFields PHP Method

validateUniqueFields() public method

Checks to see if $Username and $Email are already in use by another member.
public validateUniqueFields ( string $Username, string $Email, string $UserID = '', boolean $Return = false ) : array | boolean
$Username string
$Email string
$UserID string
$Return boolean
return array | boolean
    public function validateUniqueFields($Username, $Email, $UserID = '', $Return = false)
    {
        $Valid = true;
        $Where = [];
        if (is_numeric($UserID)) {
            $Where['UserID <> '] = $UserID;
        }
        $Result = ['Name' => true, 'Email' => true];
        // Make sure the username & email aren't already being used
        if (c('Garden.Registration.NameUnique', true) && $Username) {
            $Where['Name'] = $Username;
            $TestData = $this->getWhere($Where);
            if ($TestData->numRows() > 0) {
                $Result['Name'] = false;
                $Valid = false;
            }
            unset($Where['Name']);
        }
        if (c('Garden.Registration.EmailUnique', true) && $Email) {
            $Where['Email'] = $Email;
            $TestData = $this->getWhere($Where);
            if ($TestData->numRows() > 0) {
                $Result['Email'] = false;
                $Valid = false;
            }
        }
        if ($Return) {
            return $Result;
        } else {
            if (!$Result['Name']) {
                $this->Validation->addValidationResult('Name', 'The name you entered is already in use by another member.');
            }
            if (!$Result['Email']) {
                $this->Validation->addValidationResult('Email', 'The email you entered is in use by another member.');
            }
            return $Valid;
        }
    }
UserModel