You are here

function mo_auth_authenticate_user in Google Authenticator / 2 Factor Authentication - 2FA 7

@file This is used to authenticate user during login.

1 string reference to 'mo_auth_authenticate_user'
mo_auth_menu in ./mo_auth.module
Implements hook_menu().

File

./authenticate_user.inc, line 6
This is used to authenticate user during login.

Code

function mo_auth_authenticate_user($form, &$form_state, $user) {
  global $base_url;
  if (user_is_logged_in()) {
    drupal_goto('user');
    exit;
  }
  $form_state['uid'] = $user->uid;
  $user_email = $user->miniorange_registered_email[LANGUAGE_NONE][0]['value'];
  if (isset($_SESSION['mo_auth']['status']) && $_SESSION['mo_auth']['status'] === '1ST_FACTOR_AUTHENTICATED') {
    $challenge_response = $_SESSION['mo_auth']['mo_challenge_response'];
    $form['actions'] = array(
      '#type' => 'actions',
    );
    if (!empty($challenge_response->authType)) {
      $form['authType'] = array(
        '#type' => 'hidden',
        '#value' => $challenge_response->authType,
      );
      $authType = AuthenticationType::getAuthType($challenge_response->authType);
      $form = mo_auth_build_form($form, $user, $base_url, $authType, $challenge_response);
      unset($form['mo_message']);
    }
    else {
      $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
        '#attributes' => array(
          'class' => array(
            'element-invisible',
          ),
        ),
      );
    }
    return $form;
  }
  drupal_goto('user');
  exit;
}