You are here

function user_service_login in Services 6.2

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. 7 services/user_service/user_service.inc \user_service_login()

Login a user using the specified credentials.

Note this will transfer a plaintext password.

Parameters

$username: Username to be logged in.

$password: Password, must be plain text and not hashed.

Return value

A valid session object.

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 84
Link general user functionalities to services module.

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();
    $array = array();
    user_module_invoke('login', $array, $user);
    $return = new stdClass();
    $return->sessid = session_id();
    $return->user = $user;
    return $return;
  }
  session_destroy();
  return services_error(t('Wrong username or password.'), 401);
}