You are here

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

Makes API call for remember device

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

File

./mo_auth.module, line 766
Module file for miniOrange 2FA Module.

Code

function mo_auth_collectattributes() {
  global $base_url;

  //collecting attributes
  if (isset($_POST['miniorange_rba_attributes'])) {
    $attributes = $_POST['miniorange_rba_attributes'];
  }

  //fetching username
  if (isset($_POST['username'])) {
    $username = $_POST['username'];
  }
  $user = user_load_by_name($username);
  $form_state['uid'] = $user->uid;
  $mo_auth_rba = new MoAuthRBA();

  //collect RBA attributes
  $collect_attributes_response = json_decode($mo_auth_rba
    ->mo2f_collect_attributes($user->mail, $attributes), true);
  if (json_last_error() == JSON_ERROR_NONE) {
    if ($collect_attributes_response['status'] == 'SUCCESS') {
      $sessionUuid = $collect_attributes_response['sessionUuid'];

      //Evaluate risk
      $evaluate_risk_response = json_decode($mo_auth_rba
        ->mo2f_evaluate_risk($user->mail, $sessionUuid), true);
      if (json_last_error() == JSON_ERROR_NONE) {

        //2FA needed
        if ($evaluate_risk_response['status'] == 'WAIT_FOR_INPUT') {
          $_SESSION['mo2f_rba_status'] = array(
            'status' => $evaluate_risk_response['status'],
            'sessionUuid' => $sessionUuid,
          );
          $form = array();
          $form_state = array();

          //hook_form_alter_submit call for invoking 2FA
          mo_auth_form_alter_submit($form, $form_state, $username, true);
        }
        elseif ($evaluate_risk_response['status'] == 'SUCCESS') {
          user_login_submit(array(), $form_state);
          drupal_goto($base_url);
        }
      }
    }
  }

  //If none of the above cases are satisfied then, invoke 2FA and do not register the device.
  $form = array();
  $form_state = array();

  //hook_form_alter_submit call for invoking 2FA
  mo_auth_form_alter_submit($form, $form_state, $username, true);
}