You are here

function user_service_login in Services 6

Same name and namespace in other branches
  1. 5 services/user_service/user_service.module \user_service_login()
  2. 6.2 services/user_service/user_service.inc \user_service_login()
  3. 7 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 73
@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,
    )));
  }
  $user = user_authenticate(array(
    'name' => $username,
    'pass' => $password,
  ));
  if ($user->uid) {
    session_start();
    $return = new stdClass();
    $return->sessid = session_id();
    $return->user = $user;
    return $return;
  }
  session_destroy();
  return services_error(t('Wrong username or password.'));
}