You are here

function authenticate_user::mo_auth_forgot_phone in Google Authenticator / 2 Factor Authentication - 2FA 8

Same name and namespace in other branches
  1. 8.2 src/Form/authenticate_user.php \Drupal\miniorange_2fa\form\authenticate_user::mo_auth_forgot_phone()

File

src/Form/authenticate_user.php, line 249
This is used to authenticate user during login.

Class

authenticate_user
@file This is used to authenticate user during login.

Namespace

Drupal\miniorange_2fa\form

Code

function mo_auth_forgot_phone($form, \Drupal\Core\Form\FormStateInterface $form_state) {
  global $base_url;
  $customer = new MiniorangeCustomerProfile();
  $query_param = \Drupal::service('path.current')
    ->getPath();
  $url_parts = explode('/', $query_param);
  end($url_parts);
  $user_id = prev($url_parts);
  $custom_attribute = MoAuthUtilities::get_users_custom_attribute($user_id);
  $user_email = $custom_attribute[0]->miniorange_registered_email;
  $miniorange_user = new MiniorangeUser($customer
    ->getCustomerID(), $user_email, NULL, NULL, 'KBA');
  $auth_api_handler = new AuthenticationAPIHandler($customer
    ->getCustomerID(), $customer
    ->getAPIKey());
  $response = $auth_api_handler
    ->challenge($miniorange_user);
  if ($response->status == 'SUCCESS') {
    $session_data = array(
      'status' => $_SESSION['mo_auth']['status'],
      'mo_challenge_response' => $response,
    );
    if (session_status() == PHP_SESSION_NONE) {
      session_start();
    }
    $_SESSION['mo_auth'] = $session_data;
    $authType = AuthenticationType::getAuthType('KBA');
    $form_state
      ->setRebuild();
    return self::mo_auth_build_form($form, $base_url, $authType, $response, TRUE);
  }
  else {
    global $base_url;
    \Drupal::messenger()
      ->addMessage(t('An error occured while processing your request. Please contact administrator.'), 'error', TRUE);
    $response = new RedirectResponse($base_url);
    $response
      ->send();
  }
}