You are here

function user_service_login in Services 7

Same name and namespace in other branches
  1. 5 services/user_service/user_service.module \user_service_login()
  2. 6 services/user_service/user_service.inc \user_service_login()
  3. 6.2 services/user_service/user_service.inc \user_service_login()

Login a user

Parameters

$username: String. The username.

$password: String. The user password.

1 string reference to 'user_service_login'
user_service_service in services/user_service/user_service.module
Implementation of hook_service().

File

services/user_service/user_service.inc, line 72
@author Services Dev Team

Code

function user_service_login($username, $password) {
  global $user;
  if ($user->uid) {

    // user is already logged in
    return services_error(t('Already logged in as !user.', array(
      '!user' => $user->name,
    )), 406);
  }
  $user = user_authenticate(array(
    'name' => $username,
    'pass' => $password,
  ));
  if ($user->uid) {

    // Regenerate the session ID to prevent against session fixation attacks.
    sess_regenerate();
    module_invoke_all('user', 'login', NULL, $user);
    $return = new stdClass();
    $return->sessid = session_id();
    $return->user = $user;
    return $return;
  }
  session_destroy();
  return services_error(t('Wrong username or password.'), 401);
}