Phpauth\Auth::deleteUser PHP Method

deleteUser() public method

Allows a user to delete their account
public deleteUser ( integer $uid, string $password, string $captcha = NULL ) : array
$uid integer
$password string
$captcha string = NULL
return array $return
    public function deleteUser($uid, $password, $captcha = NULL)
    {
        $return['error'] = true;
        $block_status = $this->isBlocked();
        if ($block_status == "verify") {
            if ($this->checkCaptcha($captcha) == false) {
                $return['message'] = $this->lang["user_verify_failed"];
                return $return;
            }
        }
        if ($block_status == "block") {
            $return['message'] = $this->lang["user_blocked"];
            return $return;
        }
        $validatePassword = $this->validatePassword($password);
        if ($validatePassword['error'] == 1) {
            $this->addAttempt();
            $return['message'] = $validatePassword['message'];
            return $return;
        }
        $user = $this->getBaseUser($uid);
        if (!password_verify($password, $user['password'])) {
            $this->addAttempt();
            $return['message'] = $this->lang["password_incorrect"];
            return $return;
        }
        $query = $this->dbh->prepare("DELETE FROM {$this->config->table_users} WHERE id = ?");
        if (!$query->execute(array($uid))) {
            $return['message'] = $this->lang["system_error"] . " #05";
            return $return;
        }
        $query = $this->dbh->prepare("DELETE FROM {$this->config->table_sessions} WHERE uid = ?");
        if (!$query->execute(array($uid))) {
            $return['message'] = $this->lang["system_error"] . " #06";
            return $return;
        }
        $query = $this->dbh->prepare("DELETE FROM {$this->config->table_requests} WHERE uid = ?");
        if (!$query->execute(array($uid))) {
            $return['message'] = $this->lang["system_error"] . " #07";
            return $return;
        }
        $return['error'] = false;
        $return['message'] = $this->lang["account_deleted"];
        return $return;
    }