You are here

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

1 call to handle2FAReset()
mo_auth_inline_registration_page_five in ./mo_auth_inline_registration.inc

File

./mo_auth_inline_registration.inc, line 1327

Code

function handle2FAReset(&$form_state) {
  global $base_url;
  $storage = $form_state['storage'];
  $phone = isset($storage['page_four_values']['mo_auth_otpoversms_phone']) ? $storage['page_four_values']['mo_auth_otpoversms_phone'] : NULL;
  $method = $storage['page_three_values']['mo_auth_method'];
  $email = $storage['page_one_values']['mo_auth_user_email'];
  $customer = new MiniorangeCustomerProfile();
  $is2FAResetRequest = is2FAResetRequest($form_state);
  if ($is2FAResetRequest || backupIsDisabled($form_state) && $method != AuthenticationType::$KBA['code']) {
    $miniorange_user = new MiniorangeUser($customer
      ->getCustomerID(), $email, $phone, NULL, strpos($method, 'AUTHENTICATOR') !== FALSE ? 'GOOGLE AUTHENTICATOR' : $method);

    // update user info
    $user_api_handler = new UsersAPIHandler($customer
      ->getCustomerID(), $customer
      ->getAPIKey());
    $user_update_response = $user_api_handler
      ->update($miniorange_user);
    if ($user_update_response->status == 'SUCCESS') {
      $type = 'status';
      if (AuthenticationType::getAuthType($method)['name'] == 'OTP Over Email') {
        $updateMsg = t('Success! Your 2-Factor Authentication has been successfully ' . (backupIsDisabled() ? 'configured' : 'updated') . ' to send a One Time Passcode (OTP) to your email address for verification upon login.');
      }
      else {
        $updateMsg = t('Success! Your 2-Factor Authentication has been successfully ' . (backupIsDisabled() ? 'configured' : 'updated') . ' to ' . AuthenticationType::getAuthType($method)['name']);
      }
      $redirectUrl = variable_get('mo_auth_redirect_after_login', $base_url);
      if ($is2FAResetRequest || backupIsDisabled()) {
        saveConfigurationInDB($form_state);
        user_login_submit(array(), $form_state);
      }
    }
    else {
      $type = 'error';
      $updateMsg = 'Facing issues in ' . (backupIsDisabled() ? 'configuring' : 'updating') . ' your 2FA method. Please try in your next login.';
      $redirectUrl = backupIsDisabled() ? $base_url : variable_get('mo_auth_redirect_after_login', $base_url);
    }
    drupal_set_message($updateMsg, $type, TRUE);
    drupal_goto($redirectUrl);
    exit;
  }
}