You are here

public function BlogapiCommunicator::authenticate in Blog API 8

Performs login authentications for a user.

Parameters

$user: Drupal username.

$pass: Drupal password.

bool $return_object: Boolean var to decide on returning the user object.

Return value

bool|object Returns the user object or the user ID.

10 calls to BlogapiCommunicator::authenticate()
BlogapiCommunicator::deletePost in src/BlogapiCommunicator.php
Callback for deleting a post.
BlogapiCommunicator::editPost in src/BlogapiCommunicator.php
Callback for editing a node.
BlogapiCommunicator::getCategoryList in src/BlogapiCommunicator.php
Returns a list of available categories on a content type.
BlogapiCommunicator::getNodeCategories in src/BlogapiCommunicator.php
Returns taxonomy terms saved in the defined taxonomy field on a node.
BlogapiCommunicator::getPost in src/BlogapiCommunicator.php
Returns a loaded node object.

... See full list

File

src/BlogapiCommunicator.php, line 82

Class

BlogapiCommunicator
Class BlogapiCommunicator.

Namespace

Drupal\blogapi

Code

public function authenticate($user, $pass, $return_object = FALSE) {

  // Login check.
  $auth = \Drupal::service('user.auth');
  if ($auth
    ->authenticate($user, $pass)) {

    // Drupal permission check.
    $user_load = user_load_by_name($user);

    // Possibly return the loaded user object.
    if ($return_object) {
      return $user_load;
    }
    $id = $user_load
      ->id();
    return (int) $id;
  }

  // Return false if authentication fails.
  return FALSE;
}