miniorange_2fa_RemoveLicense.php in Google Authenticator / 2 Factor Authentication - 2FA 8
File
src/Form/miniorange_2fa_RemoveLicense.php
View source
<?php
namespace Drupal\miniorange_2fa\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Ajax\RedirectCommand;
class miniorange_2fa_RemoveLicense extends FormBase {
public function getFormId() {
return 'miniorange_2fa_remove_license';
}
public function buildForm(array $form, FormStateInterface $form_state, $options = NULL) {
$form['#prefix'] = '<div id="modal_example_form">';
$form['#suffix'] = '</div>';
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -10,
];
$form['miniorange_saml_content'] = array(
'#markup' => '<p>Are you sure you want to remove your account?<br><span id="miniorange_2fa_remove_account_warning">Warning:</span> The configurations saved will be lost.</p> ',
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['send'] = [
'#type' => 'submit',
'#value' => $this
->t('Confirm'),
'#attributes' => [
'class' => [
'use-ajax',
],
],
'#ajax' => [
'callback' => [
$this,
'submitModalFormAjax',
],
'event' => 'click',
],
];
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
return $form;
}
public function submitModalFormAjax(array $form, FormStateInterface $form_state) {
$response = new AjaxResponse();
if ($form_state
->hasAnyErrors()) {
$response
->addCommand(new ReplaceCommand('#modal_example_form', $form));
}
else {
if (\Drupal::config('miniorange_2fa.settings')
->get('mo_auth_2fa_license_type') != NULL) {
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_customer_admin_email')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_customer_admin_phone')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_customer_id')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_customer_api_key')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_customer_token_key')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_customer_app_secret')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_status')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_2fa_license_type')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_2fa_license_plan')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_2fa_license_no_of_users')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_enable_two_factor')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_enforce_inline_registration')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_auth_use_only_2nd_factor')
->save();
\Drupal::configFactory()
->getEditable('miniorange_2fa.settings')
->clear('mo_user_limit_exceed')
->save();
$connection = \Drupal::database();
$connection
->truncate('UserAuthenticationType')
->execute();
\Drupal::messenger()
->addMessage(t('Your Account Has Been Removed Successfully!'), 'status');
$_POST['value_check'] = 'False';
}
$response
->addCommand(new RedirectCommand(\Drupal\Core\Url::fromRoute('miniorange_2fa.customer_setup')
->toString()));
}
return $response;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
protected function getEditableConfigNames() {
return [
'config.miniorange_2fa_remove_license',
];
}
}