You are here

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

2 calls to saveConfigurationInDB()
handle2FAReset in ./mo_auth_inline_registration.inc
handle_page_five_submit in ./mo_auth_inline_registration.inc

File

./mo_auth_inline_registration.inc, line 1374

Code

function saveConfigurationInDB(&$form_state, $isKba = FALSE) {
  $user = user_load($form_state['uid']);
  $method = $form_state['storage']['page_three_values']['mo_auth_method'];
  $user_email = $form_state['storage']['page_one_values']['mo_auth_user_email'];
  $user->miniorange_registered_email[LANGUAGE_NONE][0]['value'] = $user_email;
  $configured_methods = mo_auth_get_configured_methods($user->uid);
  if ($isKba && !in_array(AuthenticationType::$KBA['code'], $configured_methods)) {
    array_push($configured_methods, AuthenticationType::$KBA['code']);
  }

  /**
   * Delete all the configured TOTP methods as only one can be used at a time
   */
  $authenticators = array(
    'MICROSOFT AUTHENTICATOR',
    'GOOGLE AUTHENTICATOR',
    'AUTHY AUTHENTICATOR',
    'LASTPASS AUTHENTICATOR',
  );
  $configured_methods = array_values(array_diff($configured_methods, $authenticators));
  array_push($configured_methods, $method);
  array_push($configured_methods, AuthenticationType::$EMAIL_VERIFICATION['code']);
  $user->configured_auth_methods[LANGUAGE_NONE] = array();
  $configured_methods = array_unique($configured_methods);
  foreach ($configured_methods as $value) {
    array_push($user->configured_auth_methods[LANGUAGE_NONE], array(
      'value' => $value,
    ));
  }
  user_save($user);
}