Remove all linked logins that are using issuers that have been deleted.

@param int $issuerid The issuer id of the issuer to check, or false to check all (defaults to all)
@return boolean
333180
public static function delete_orphaned($issuerid = false) {
        global $DB;
        // Delete any linked_login entries with a issuerid
        // which does not exist in the issuer table.
        // In the left join, the issuer id will be null
        // where a match linked_login.issuerid is not found.
        $sql = "DELETE FROM {" . self::TABLE . "}
                 WHERE issuerid NOT IN (SELECT id FROM {" . \core\oauth2\issuer::TABLE . "})";
        $params = [];
        if (!empty($issuerid)) {
            $sql .= ' AND issuerid = ?';
            $params['issuerid'] = $issuerid;
        }
        return $DB->execute($sql, $params);
    }
47009
public function isSelfIssued()
    {
        if (!$this->issuer) {
            return false;
        }
        if (!$this->contact) {
            return false;
        }
        if (!$this->contact->user) {
            return false;
        }

        return $this->issuer->id == $this->contact->user->id;
    }
1163212
public function deleteUsers($userids){
	    if (!$userids) return false;
	    $data = array('useridlist'=>$userids);
	    if (!$this->access_token && !$this->checkAuth()) return false;
	    $result = $this->http_post(self::API_URL_PREFIX.self::USER_BATCHDELETE_URL.'access_token='.$this->access_token,self::json_encode($data));
	    if ($result)
	    {
	        $json = json_decode($result,true);
	        if (!$json || !empty($json['errcode']) || $json['errcode']!=0) {
	            $this->errCode = $json['errcode'];
	            $this->errMsg = $json['errmsg'];
	            return false;
	        }
	        return $json;
	    }
	    return false;
	}
502767
public static function ClearAuthentication($guid = "CURRENT_USER")
	{
		self::Init();
		self::$user = null;
		unset($_SESSION[$guid]);
		
		self::UnsetAllSessionVars();
		
		@session_destroy();
	}
548772
public static function create_new_confirmed_account($userinfo, $issuer) {
        global $CFG, $DB;
        require_once($CFG->dirroot.'/user/profile/lib.php');
        require_once($CFG->dirroot.'/user/lib.php');

        $user = new stdClass();
        $user->username = $userinfo['username'];
        $user->email = $userinfo['email'];
        $user->auth = 'oauth2';
        $user->mnethostid = $CFG->mnet_localhost_id;
        $user->lastname = isset($userinfo['lastname']) ? $userinfo['lastname'] : '';
        $user->firstname = isset($userinfo['firstname']) ? $userinfo['firstname'] : '';
        $user->url = isset($userinfo['url']) ? $userinfo['url'] : '';
        $user->alternatename = isset($userinfo['alternatename']) ? $userinfo['alternatename'] : '';
        $user->secret = random_string(15);

        $user->password = '';
        // This user is confirmed.
        $user->confirmed = 1;

        $user->id = user_create_user($user, false, true);

        // The linked account is pre-confirmed.
        $record = new stdClass();
        $record->issuerid = $issuer->get('id');
        $record->username = $userinfo['username'];
        $record->userid = $user->id;
        $record->email = $userinfo['email'];
        $record->confirmtoken = '';
        $record->confirmtokenexpires = 0;

        $linkedlogin = new linked_login(0, $record);
        $linkedlogin->create();

        return $user;
    }
115779
static function removeIdentity(\Db\Connection $db, User $user, $openid) {
    if (!$user) {
      throw new \InvalidArgumentException("No user provided.");
    }

    $q = $db->prepare("DELETE FROM user_openid_identities WHERE user_id=? AND identity=? LIMIT 1");
    return $q->execute(array($user->getId(), $openid));
  }
1288543
def delete_issue_link(self, id):
        
        url = self._get_url('issueLink') + "/" + id
        return self._session.delete(url)
1023408
public void clearTenant(String tenantId) {
        String index = getIndex(tenantId);

        synchronized (knownIndices) {
            IndicesAdminClient indices = client.admin().indices();

            boolean indexExists = indices.prepareExists(index)
                    .execute()
                    .actionGet()
                    .isExists();

            if (indexExists) {
                indices.prepareDelete(index)
                        .execute()
                        .actionGet();
            }

            knownIndices.remove(index);
        }
    }
1119080
public function authz_delete_user($uid) {
		$udata = $this->user_data;
		if ($udata['uid'] == 1 && $uid != 1)
			return true;
		if ($udata['uid'] == $uid)
			return true;
		return false;
	}
288122
public function endpoints_table($endpoints, $issuerid) {
        global $CFG;

        $table = new html_table();
        $table->head  = [
            get_string('name'),
            get_string('url'),
            get_string('edit'),
        ];
        $table->attributes['class'] = 'admintable generaltable';
        $data = [];

        $index = 0;

        foreach ($endpoints as $endpoint) {
            // Name.
            $name = $endpoint->get('name');
            $namecell = new html_table_cell(s($name));
            $namecell->header = true;

            // Url.
            $url = $endpoint->get('url');
            $urlcell = new html_table_cell(s($url));

            $links = '';
            // Action links.
            $editparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'edit'];
            $editurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $editparams);
            $editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
            $links .= ' ' . $editlink;

            // Delete.
            $deleteparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'delete'];
            $deleteurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $deleteparams);
            $deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
            $links .= ' ' . $deletelink;

            $editcell = new html_table_cell($links);

            $row = new html_table_row([
                $namecell,
                $urlcell,
                $editcell,
            ]);

            $data[] = $row;
            $index++;
        }
        $table->data = $data;
        return html_writer::table($table);
    }
584972
private function is_ready_for_login_page(\core\oauth2\issuer $issuer) {
        return $issuer->get('enabled') &&
                $issuer->is_configured() &&
                !empty($issuer->get('showonloginpage'));
    }
480507
public function clear($username, $repository, $issue)
    {
        return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');
    }
982567
public static function logout($campaignID) {
    $campaignIDs = [];
    $membershipIDs = [];
    $fullNames = [];
    $memberIDs = [];

    $request = \Drupal::request();
    $session = $request->getSession();

    if (!empty($session->get('openy_campaign'))) {
      $openyCampaignSession = $session->get('openy_campaign');
      $campaignIDs = $openyCampaignSession['campaign_ids'];
      $membershipIDs = $openyCampaignSession['membership_ids'];
      $fullNames = $openyCampaignSession['full_names'];
      $memberIDs = $openyCampaignSession['member_ids'];
    }

    // Delete Campaign ID, Membership ID, internal Member ID and Full name from SESSION.
    if (in_array($campaignID, $campaignIDs)) {
      $newCampaignIDs = array_diff($campaignIDs, [$campaignID]);

      $membershipID = $membershipIDs[$campaignID];
      $newMembershipIDs = array_diff($membershipIDs, [$membershipID]);

      $fullName = $fullNames[$campaignID];
      $newFullNames = array_diff($fullNames, [$fullName]);

      $memberID = $fullNames[$campaignID];
      $newMemberIDs = array_diff($memberIDs, [$memberID]);

      Cache::invalidateTags(['member:' . $memberID]);

      $session->set('openy_campaign', [
        'campaign_ids' => $newCampaignIDs,
        'membership_ids' => $newMembershipIDs,
        'full_names' => $newFullNames,
        'member_ids' => $newMemberIDs,
      ]);
    }
  }
1199398
protected function deleteExistingSessions($uid)
    {
        $query = "DELETE FROM {$this->config->table_sessions} WHERE uid = :uid";
        $query_prepared = $this->dbh->prepare($query);
        $query_prepared->execute(['uid' => $uid]);

        return $query_prepared->rowCount() > 0;
    }
986590
public function removeAll()
    {
        /** @var Connection $connection */
        $connection = $this->entityManager->getConnection();

        $isMySQL = $connection->getDriver()->getName() === 'pdo_mysql';
        if ($isMySQL) {
            $connection->query('SET FOREIGN_KEY_CHECKS=0');
        }

        $connection->query("DELETE FROM neos_neos_eventlog_domain_model_event WHERE dtype = 'ttree_contentrepositoryimporter_event'");

        if ($isMySQL) {
            $connection->query('SET FOREIGN_KEY_CHECKS=1');
        }
    }
1152448
public function canDelete($user_guid = 0) {
		
		$user_guid = (int) $user_guid;
		if (empty($user_guid)) {
			$user_guid = elgg_get_logged_in_user_guid();
		}
		
		return elgg_is_admin_user($user_guid);
	}
1086083
public static function deleteAllUsers()
	{
		$conn = self::getLDO();

		if (empty($conn))
		{
			self::$errors['fatal'][] = 'LDAP connection failed';
			return self::$errors;
		}

		// delete all old hubAccount schema based user entries
		$ldap_params = \Component::params('com_system');
		$hubLDAPBaseDN = $ldap_params->get('ldap_basedn', '');

		$dn = "ou=users," . $hubLDAPBaseDN;
		$filter = '(objectclass=hubAccount)';

		$sr = ldap_search($conn, $dn, $filter, array('uid'), 0, 0, 0);

		$uids = array();

		if ($sr !== false)
		{
			if (ldap_count_entries($conn, $sr) !== false)
			{
				$entry = ldap_first_entry($conn, $sr);

				while ($entry !== false)
				{
					$attr = ldap_get_attributes($conn, $entry);

					$uids[] = $attr['uid'][0];

					$entry = ldap_next_entry($conn, $entry);
				}
			}
		}

		foreach ($uids as $uid)
		{
			$dn = "uid=$uid," . "ou=users," . $hubLDAPBaseDN;
			$result = ldap_delete($conn, $dn);

			if ($result !== true)
			{
				self::$errors['warning'][] = ldap_error($conn);
			}
			else
			{
				++self::$success['deleted'];
			}
		}

		// delete all entries that have mysql counterparts
		// @TODO: chunk this to 1000 groups at a time
		$db = \App::get('db');

		// Negative numbers exist as usernames for placeholders, these aren't in ldap
		// In fact we can't even search for them without causing an error
		$query = "SELECT username FROM `#__users` where (username not REGEXP '^-?\d+$' and username REGEXP '^[a-zA-Z]')";

		$db->setQuery($query);

		$result = $db->loadColumn();

		if ($result === false)
		{
			return false;
		}

		foreach ($result as $row)
		{
			$dn = "uid=$row," .  "ou=users," . $hubLDAPBaseDN;

			// see if item to be deleted is there
			$count = 0;
			$sr = ldap_search($conn, "ou=users," . $hubLDAPBaseDN, "uid=$row");

			if ($sr !== false)
			{
				if (ldap_count_entries($conn, $sr) !== false)
				{
					$count = ldap_count_entries($conn, $sr);
				}
			}

			if ($count > 0)
			{
				$result = ldap_delete($conn, $dn);
				if ($result !== true)
				{
					self::$errors['warning'][] = ldap_error($conn);
				}
				else
				{
					++self::$success['deleted'];
				}
			}
		}

		// delete any remaining items with gid > 1000
		$dn = "ou=users," . $hubLDAPBaseDN;
		$filter = '(&(objectclass=posixAccoiunt)(uidNumber>=1000))';

		$sr = ldap_search($conn, $dn, $filter, array('uid'), 0, 0, 0);

		$uids = array();

		if ($sr !== false)
		{
			if (ldap_count_entries($conn, $sr) !== false)
			{
				$entry = ldap_first_entry($conn, $sr);

				while ($entry !== false)
				{
					$attr = ldap_get_attributes($conn, $firstentry);

					$uids[] = $attr['uid'][0];

					$entry = ldap_next_entry($conn, $entry);
				}
			}
		}

		foreach ($uids as $uid)
		{
			$dn = "uid=$uid," . "ou=users," . $hubLDAPBaseDN;
			$result = ldap_delete($conn, $dn);

			if ($result !== true)
			{
				self::$errors['warning'][] = ldap_error($conn);
			}
			else
			{
				++self::$success['deleted'];
			}
		}

		if (!empty(self::$errors['fatal'][0]) || !empty(self::$errors['warning'][0]))
		{
			return self::$errors;
		}
		else
		{
			return self::$success;
		}
	}