You are here

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

2 calls to handle_page_five_submit()
handle_page_four_submit in ./mo_auth_inline_registration.inc
mo_auth_inline_registration_submit in ./mo_auth_inline_registration.inc

File

./mo_auth_inline_registration.inc, line 789

Code

function handle_page_five_submit($form, &$form_state) {
  global $base_url;
  $form_state['rebuild'] = TRUE;
  $user_email = $form_state['storage']['page_one_values']['mo_auth_user_email'];
  $user_phone = isset($form_state['storage']['page_four_values']['mo_auth_otpoversms_phone']) ? $form_state['storage']['page_four_values']['mo_auth_otpoversms_phone'] : NULL;
  $question1 = $form['mo_auth_question1']['#value'];
  $answer1 = $form['mo_auth_answer1']['#value'];
  $question2 = $form['mo_auth_question2']['#value'];
  $answer2 = $form['mo_auth_answer2']['#value'];
  $question3 = $form['mo_auth_question3']['#value'];
  $answer3 = $form['mo_auth_answer3']['#value'];
  $qa1 = array(
    "question" => $question1,
    "answer" => $answer1,
  );
  $qa2 = array(
    "question" => $question2,
    "answer" => $answer2,
  );
  $qa3 = array(
    "question" => $question3,
    "answer" => $answer3,
  );
  $kba = array(
    $qa1,
    $qa2,
    $qa3,
  );
  $method = $form_state['storage']['page_three_values']['mo_auth_method'];
  $customer = new MiniorangeCustomerProfile();
  $miniorange_user = new MiniorangeUser($customer
    ->getCustomerID(), $user_email, $user_phone, NULL, $method);
  $auth_api_handler = new AuthenticationAPIHandler($customer
    ->getCustomerID(), $customer
    ->getAPIKey());
  $response = $auth_api_handler
    ->register($miniorange_user, AuthenticationType::$KBA['code'], NULL, NULL, $kba);
  if ($response->status == 'SUCCESS') {
    $user_api_handler = new UsersAPIHandler($customer
      ->getCustomerID(), $customer
      ->getAPIKey());
    $user_update_response = $user_api_handler
      ->update($miniorange_user);
    if ($user_update_response->status == 'SUCCESS') {
      saveConfigurationInDB($form_state, TRUE);
      if (is2FAResetRequest($form_state)) {
        drupal_set_message('Successfully updated your 2FA method to ' . AuthenticationType::$KBA['name']);
        drupal_goto(variable_get('mo_auth_redirect_after_login', $base_url));
        exit;
      }
      $registered_emails = variable_get('mo_auth_users_registered_emails');
      $registered_emails[$user_email] = TRUE;
      variable_set('mo_auth_users_registered_emails', $registered_emails);
      user_login_submit(array(), $form_state);
      $mo_redirect_after_login = variable_get('mo_auth_redirect_after_login', '');
      $currentpath = isset($mo_redirect_after_login) && !empty($mo_redirect_after_login) ? $mo_redirect_after_login : (isset($_SESSION['moDestination']) ? $base_url . '/' . $_SESSION['moDestination'] : $base_url);
      drupal_goto($currentpath);
    }
  }

  // Error out. Send to login.
}