You are here

function urllogin_testuid in urllogin 8

Same name and namespace in other branches
  1. 2.x urllogin.module \urllogin_testuid()

Tests to see if UID can be logged on.

Parameters

int $uid: UID to be tested.

string $resultmsg: Contains resultmsg message if function fails.

Return value

object If sucessful, loaded account of user Else NULL.

2 calls to urllogin_testuid()
UrlloginController::linkTest in src/Controller/UrlloginController.php
Diagnostic test page for setting up urllogin urls.
UrlloginController::login in src/Controller/UrlloginController.php
This is the function that actually performs the login.

File

./urllogin.module, line 71
Module file for Urllogin.

Code

function urllogin_testuid($uid, &$resultmsg) {
  if ($uid < 2) {
    $resultmsg = t('UID is %uid - cannot login as user 0 or 1', [
      '%uid' => $uid,
    ]);
    return NULL;
  }
  $account = User::load($uid);
  if (!$account) {
    $resultmsg = t('User %uid does not exist', [
      '%uid' => $uid,
    ]);
    return NULL;
  }
  if (!$account
    ->hasPermission('login via url')) {
    $resultmsg = t('User %uid denied access', [
      '%uid' => $uid,
    ]);
    return NULL;
  }
  $resultmsg = t('User %username (%uid) successfully validated', [
    '%username' => $account
      ->getDisplayName(),
    '%uid' => $uid,
  ]);
  return $account;
}