login user after form submit I have a form that one of fields is mail field, when form submit I check that email if not belongs to any user I create a user  and assign that node to the created user, Then I want logged in that user automatically after user create a node.

I have below solution  but not work.

function mymodule_form_node_form_alter(&amp;$form,&amp;$form_state,$form_id)
  {
 if($form_id=="my_content_type")
 {
if($user-&gt;uid==0){
        array_unshift($form['#submit'], '_tgdev_ss_submit');
   $form['actions']['submit']['#submit'][]= '_tgdev_listing_suserlogin';
  }

   }
} 

function _tgdev_ss_submit(&amp;$form, &amp;$form_state)
{
        $mail=form_state['values']['field_mail']['und'][0]['mail'];
    if(!user_load_by_mail($mail)){         
        $account = new stdClass;
        $account-&gt;is_new = TRUE;
        $account-&gt;name = _tgdev_username_pattern_generate();
        $account-&gt;pass = user_password(8);
        $account-&gt;mail = $form_state['values']['field_email']['und'][0]['email'];
        $account-&gt;init = $form_state['values']['field_email']['und'][0]['email'];
        $account-&gt;status = TRUE;
        $account-&gt;roles = array(DRUPAL_AUTHENTICATED_RID =&gt; TRUE);
        user_save($account);
        $op = 'register_no_approval_required';
        $status = _user_mail_notify($op, $account);
        $form_state['values']['uid'] = $account-&gt;uid;
        $form_state['values']['name'] = $account-&gt;name
        }
 }

function _tgdev_listing_suserlogin($form,$form_state)
{
//$user_obj = user_load_by_mail($form_state['values']['field_email']['und'][0]['email']);
$form_state['uid'] = $form_state['values']['uid'];
user_login_submit(array(), $form_state);
// ym($form_state,'message');
 $form_state['redirect']='node/'.$form_state['nid'];
 }
}


appreciate any help or suggestion
You could use something like auto_login_url and generate a url then redirect the user to that URL before you go to the node. This is mainly an API module that allows you to generate URL login links so you will have to code the solution. There are a couple of other URL login modules out there but this one has a pretty easy API to handle with no large learning curve.
From the module page:

Creates auto login URLs on demand and through tokens.
This is mostly a developer's module. The better use for me is to convert all links of a specific text to auto login links.

Similar module urllogin