I have tried far too many variations to list here, but the basic point is I cannot get the user logged in immediately after registration via Services. I have tried a fresh Drupal 7.33 install with only Services 7.x.3.11 enabled and the default resource settings provided by drupalgap 7.x.1.9

When I register using the Drupal interface, the user is created, the session opened, and I land on my profile page logged in.


When I call the Services endpoint /services/user/register.json, Drupal creates the account but the session does not persist. See my screenshots below.

enter image description here

How can I either A. get the session to persist for subsequent Service resource calls OR B. hook to add the user's or auto-generated password back into the json response so I can programmatically resubmit the /login.json form client-side (which does persist) ?

This question how could the global $user be different between the Drupal interface and Services module? describes my same problem using LoginToboggan.

In my screenshot you'll see a debug line called "login debug". It comes from line 333 of "/sites/all/modules/logintoboggan/logintoboggan.module" where I've tried all of this to no avail...

function logintoboggan_process_login($account, &$edit, $redirect = array()){
  global $user;

  $user = user_load($account->uid);

//watchdog('login debug', json_encode($account)); 
watchdog('login debug', json_encode($edit));

  //user_login_submit(array(), array('uid' => $account->uid));

//  $user = user_load($account->uid);
//  $user->token = drupal_get_token('services'); // WE HAVE A TOKEN ALTHOUGH I DOUBT THIS WOULD WORK IN TERMS OF SESSION PERSISTANCE
//  user_login_finalize($edit);
//  module_invoke_all('hook_user_login');
//  module_invoke_all('tripchi_user_login');
//  module_invoke_all('logintoboggan_user_login');
  • @Clive, is it against terms to solicite paid help here?
    – E.A.T
    Dec 17, 2014 at 9:05
  • It is @EliATaylor, I was just leaving a comment. We're only interested in the question and the answer here, anything else (soliciting paid work, asking for links to tutorials, or basically most other things that happen off-site) is a distraction from that and something we guard against. All we really want is a good question (which we've got here, awesome) and a good answer (which hopefully you'll get)
    – Clive
    Dec 17, 2014 at 9:10
  • you've helped me too many times to complain here, but gosh @clive. i could take that conversation offline and not clutter this screen except once we resolve it. Also here, I don't even have the reputation to use the chat feature. Can I trade some from StackOverflow? Not even link my github link to the repo?
    – E.A.T
    Dec 17, 2014 at 9:19
  • 1
    Not even :) Quite simply we're not a support forum, and anything that isn't "question" or "answer" goes against our mission of creating a high quality repository of knowledge about Drupal. Anything that's necessary to answer the question needs to be in the question itself, because if it isn't, the question becomes useless as soon as the off-site links go dead, or the issue is fixed. The rules may seem arbitrary, or harsh even, but they've been proven necessary by the Stack Exchange model as a whole over a number of years now. If you remember it's just Q+A here, there'll never be a problem
    – Clive
    Dec 17, 2014 at 9:24
  • Regarding your rep for chatting - you're very close to that now, and I suspect this question will attract a few upvotes as it's well written. They will come with time. That's the other thing I should mention, we have no sense of time here as such - we'd rather questions took longer to answer but in a higher quality way than quick-and-basic responses. Not that we encourage people to be slow or anything like that, but if you need something accomplished in a time-sensitive manner it's not a good idea to hedge your bets on that happening here, since we're not focused on it
    – Clive
    Dec 17, 2014 at 9:29

2 Answers 2


Not sure if you need an answer at this point (or if this is even one), but it looks like you have "Require e-mail verification when a visitor creates an account" turned on?

In your image, in the second window (where you see the message from drupal_set_message()), it says that an email was sent and you will need to follow instructions to gain full message.

To turn this off, navigate to /admin/config/people/accounts and uncheck Require e-mail verification when a visitor creates an account.

If you look at the user table in the database, the status column should show a 1 for enabled, 0 for disabled (meaning he hasn't clicked on the link in the email).

Hope it helps!

  • It didn't work even if you make registered users active by default Dec 1, 2015 at 12:29

It's working fine for me you can use following code

global $user;
if ($user->uid) {
    // user is already logged in
    return services_error(t('Already logged in as @user.', array('@user' => $user->name)), 406);

// Check if account is active.
if (user_is_blocked($username)) {
    return services_error(t('The username %name has not been activated or is blocked.', array('%name' => $username)), 403);

// Emulate drupal native flood control: check for flood condition.
$flood_state = array();
if (variable_get('services_flood_control_enabled', TRUE)) {
    $flood_state = _user_resource_flood_control_precheck($username);

// Only authenticate if a flood condition was not detected.
if (empty($flood_state['flood_control_triggered'])) {
    $uid = user_authenticate($username, $password);
else {
    $uid = FALSE;

// Emulate drupal native flood control: register flood event, and throw error
// if a flood condition was previously detected
if (variable_get('services_flood_control_enabled', TRUE)) {
    $flood_state['uid'] = $uid;

if ($uid) {
    $user = user_load($uid);
    if ($user->uid) {

        $return = new stdClass();
        $return->sessid = session_id();
        $return->session_name = session_name();
        $return->token = drupal_get_token('services');
        $account = clone $user;
        $return->user = $account;

        return $return;
watchdog('user', 'Invalid login attempt for %username.', array('%username' => $username));
return services_error(t('Wrong username or password.'), 401);

pass user email id and password then it will returns all the required value like session id ,session name ,token , user uid

  • It creates new sessions but no record in sessions table inserted, So still no valid session Oct 18, 2015 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.