function _user_resource_login in Services 6.3
Same name and namespace in other branches
- 7.3 resources/user_resource.inc \_user_resource_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_resource_login'
- _user_resource_definition in resources/
user_resource.inc - @file This file will define the resources for dealing with the user object
File
- resources/
user_resource.inc, line 372 - This file will define the resources for dealing with the user object
Code
function _user_resource_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);
}
if (user_is_blocked($username)) {
return services_error(t('@user is blocked.', array(
'@user' => $username,
)), 406);
}
user_authenticate(array(
'name' => $username,
'pass' => $password,
));
if (isset($user->uid) && $user->uid) {
// Regenerate the session ID to prevent against session fixation attacks.
sess_regenerate();
$return = new stdClass();
$return->sessid = session_id();
$return->session_name = session_name();
services_remove_user_data($user);
$return->user = $user;
return $return;
}
session_destroy();
return services_error(t('Wrong username or password.'), 401);
}