7 – user_login_submit does not work when called in an inner function

We have a common registry feature that is used by several parts of our app. After successful registration, the user is logged on. However, if a user completes this project through a browser on the web, for some reason he is not properly logged on.

$result = register_user($registration_data);
if($result('success') == true) {
    // Log user in for web.
    $account = $result('user');
    $uid = $account->uid;
    $account_id_array = array('uid' => $uid);
    user_login_submit(array(), $account_id_array);

At the end we have to sign the user on the form Submit

function agfe_registration_step_three_submit($form, &$form_state) {
...
  $result = register_user($registration_data);
  if($result('success') == true) {
    // Log user in for web.
    $account = $result('user');
    $uid = $account->uid;
    $account_id_array = array('uid' => $uid);
    user_login_submit(array(), $account_id_array);
    $user = user_load($uid);
    user_login_finalize();
    drupal_goto('dashboard');

Why do we have to do that? should not be the first user_login_submit Full authentication and user setup to use the website?