You are here

public function MoAuthCustomerSetup::buildForm in Google Authenticator / 2 Factor Authentication - 2FA 8

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

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/MoAuthCustomerSetup.php, line 27
Contains form for customer setup.

Class

MoAuthCustomerSetup
Customer setup form().

Namespace

Drupal\miniorange_2fa\Form

Code

public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
  global $base_url;
  $user_obj = User::load(\Drupal::currentUser()
    ->id());
  $user_id = $user_obj
    ->id();
  $current_status = \Drupal::config('miniorange_2fa.settings')
    ->get('mo_auth_status');
  $form['markup_library'] = array(
    '#attached' => array(
      'library' => 'miniorange_2fa/miniorange_2fa.license',
    ),
  );
  if ($current_status == 'VALIDATE_OTP') {
    $form['markup_top_2'] = array(
      '#markup' => '<div class="mo_saml_table_layout_1"><div class="mo_saml_table_layout mo_saml_container">',
    );
    $form['mo_auth_customer_otp_token'] = array(
      '#type' => 'textfield',
      '#title' => t('Please enter the OTP you received<span style="color: red">*</span>'),
      '#attributes' => array(
        'autofocus' => 'true',
      ),
      '#maxlength' => 6,
      '#suffix' => '<br>',
    );
    $form['mo_auth_customer_validate_otp_button'] = array(
      '#type' => 'submit',
      '#value' => t('Validate OTP'),
      '#submit' => array(
        '::mo_auth_validate_otp_submit',
      ),
    );
    $form['Mo_auth_customer_setup_resendotp'] = array(
      '#type' => 'submit',
      '#value' => t('Resend OTP'),
      '#submit' => array(
        '::mo_auth_resend_otp',
      ),
    );
    $form['Mo_auth_customer_setup_back'] = array(
      '#type' => 'submit',
      '#value' => t('Back'),
      '#submit' => array(
        '::mo_auth_back',
      ),
    );
    $form['main_layout_div_end'] = array(
      '#markup' => '<br><br><br><br>
                        </div>',
    );
    MoAuthUtilities::AddsupportTab($form, $form_state);
    return $form;
  }
  elseif ($current_status == 'PLUGIN_CONFIGURATION') {

    // Show customer configuration here.
    $utilities = new MoAuthUtilities();
    $custom_attribute = $utilities::get_users_custom_attribute($user_id);
    $user_email = $custom_attribute[0]->miniorange_registered_email;
    $customer = new MiniorangeCustomerProfile();
    $user_api_handler = new UsersAPIHandler($customer
      ->getCustomerID(), $customer
      ->getAPIKey());
    $miniorange_user = new MiniorangeUser($customer
      ->getCustomerID(), $user_email, '', '', '');
    $response = $user_api_handler
      ->get($miniorange_user);
    $authType = AuthenticationType::getAuthType($response->authType);
    $form['markup_top_1'] = array(
      '#markup' => '<div class="mo_saml_table_layout_1"><div id="Register_Section" class="mo_saml_table_layout mo_saml_container">',
    );

    /* Show message if user creation limit exceeded */
    $mo_user_limit = \Drupal::configFactory()
      ->getEditable('miniorange_2fa.settings')
      ->get('mo_user_limit_exceed');
    if (isset($mo_user_limit) && $mo_user_limit == TRUE) {
      $form['markup_top_2'] = array(
        '#markup' => '<div class="users_limit_exceeded_message">Your user creation limit has been completed. Please upgrade your license to add more users. Please ignore if already upgraded. </div>',
      );
    }
    $form['markup_top'] = array(
      '#markup' => '<div class="mo_saml_welcome_message">Thank you for registering with miniOrange</div><h4>Your Profile: </h4>',
    );
    $header = array(
      'attribute' => array(
        'data' => t('Attribute'),
      ),
      'value' => array(
        'data' => t('Value'),
      ),
    );
    $options = array();
    $options[0] = array(
      'attribute' => '2 Factor Registered Email',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_customer_admin_email'),
    );
    $options[1] = array(
      'attribute' => 'Activated 2nd Factor',
      'value' => $authType['name'],
    );
    $options[2] = array(
      'attribute' => 'Xecurify Registered Email',
      'value' => $user_email,
    );
    $options[3] = array(
      'attribute' => 'Customer ID',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_customer_id'),
    );
    $options[4] = array(
      'attribute' => 'API Key',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_customer_api_key'),
    );
    $options[5] = array(
      'attribute' => 'Token Key',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_customer_token_key'),
    );
    $options[6] = array(
      'attribute' => 'App Secret',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_customer_app_secret'),
    );
    $form['fieldset']['customerinfo'] = array(
      '#theme' => 'table',
      '#header' => $header,
      '#rows' => $options,
    );
    $license_header = array(
      'attribute' => array(
        'data' => t('Attribute'),
      ),
      'value' => array(
        'data' => t('Value'),
      ),
    );
    $license_options = array();
    $license_options[0] = array(
      'attribute' => 'License Type',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_2fa_license_type') == '' ? 'DEMO' : \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_2fa_license_type'),
    );
    $license_options[1] = array(
      'attribute' => 'License Plan',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_2fa_license_plan') == '' ? 'DEMO' : \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_2fa_license_plan'),
    );
    $license_options[2] = array(
      'attribute' => 'No. of Users',
      'value' => \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_2fa_license_no_of_users') == '' ? 1 : \Drupal::config('miniorange_2fa.settings')
        ->get('mo_auth_2fa_license_no_of_users'),
    );
    $form['fieldset']['customer-license'] = array(
      '#theme' => 'table',
      '#header' => $license_header,
      '#rows' => $license_options,
      '#prefix' => '<div style="margin-top: 20px;"><h4>Your license info: </h4></div>',
    );
    $form['fecth_customer_license'] = array(
      '#type' => 'submit',
      '#value' => t('Check License'),
      '#submit' => array(
        '::mo_auth_fetch_customer_license',
      ),
    );
    $form['miniorange_saml_customer_Remove_Account_info'] = array(
      '#markup' => '<br><br><br><br><br/><h4>Remove Account:</h4><p>This section will help you to remove your current
                            logged in account. </p>',
    );
    $form['miniorange_saml_customer_Remove_Account'] = array(
      '#type' => 'link',
      '#title' => $this
        ->t('Remove Account'),
      '#url' => \Drupal\Core\Url::fromRoute('miniorange_2fa.modal_form'),
      '#attributes' => [
        'class' => [
          'use-ajax',
          'button',
        ],
      ],
      '#suffix' => '<br><br><hr><br><br></div>',
    );
    $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    MoAuthUtilities::AddsupportTab($form, $form_state);
    return $form;
  }
  $url = $base_url . '/admin/config/people/miniorange_2fa/customer_setup';
  $tab = isset($_GET['tab']) && $_GET['tab'] == 'login' ? $_GET['tab'] : 'register';
  $form['markup_start'] = array(
    '#markup' => '<div class="mo_saml_table_layout_1"><div class="mo_saml_table_layout mo_saml_container">
                         ',
  );
  if ($tab == 'register') {
    $form['markup_msg_1'] = array(
      '#markup' => '<h2>Register with mini<span class="mo_orange"><b>O</b></span>range</h2><hr><br>
                            <div class="mo_saml_highlight_background_note_1">Just complete the short registration below to configure the Two-Factor Module. Please enter a valid email ID that you have access to.
                              You will be able to move forward after verifying an OTP that we will send to this email.</div>
                        ',
    );
    $form['Mo_auth_customer_register_username'] = array(
      '#type' => 'textfield',
      '#id' => "email_id",
      '#title' => t('Email<span style="color: red">*</span>'),
      '#description' => t('<b>Note:</b> Use valid EmailId. (We discourage the use of disposable emails)'),
      '#attributes' => array(
        'autofocus' => 'true',
      ),
    );
    $form['Mo_auth_customer_register_phone'] = array(
      '#type' => 'textfield',
      '#title' => t('Phone'),
      '#id' => 'query_phone',
      '#description' => t('<b>Note:</b> We will only call if you need support.'),
      '#attributes' => array(
        'class' => array(
          'query_phone',
        ),
      ),
    );
    $form['Mo_auth_customer_register_password'] = array(
      '#type' => 'password_confirm',
    );
    $form['Mo_auth_customer_register_button'] = array(
      '#type' => 'submit',
      '#value' => t('Register'),
      '#limit_validation_errors' => array(),
      '#prefix' => '<br><div class="ns_row"><div class="ns_name">',
      '#suffix' => '</div>',
    );
    $form['already_account_link'] = array(
      '#markup' => '<a href="' . $url . '/?tab=login" class="ns_display"><b>Already have an account ?</b></a>',
      '#prefix' => '<div class="ns_value">',
      '#suffix' => '</div></div><br><br></div>',
    );
  }
  else {
    $form['markup_15'] = array(
      '#markup' => '<h2>Login with mini<span class="mo_orange"><b>O</b></span>range</h2><hr>',
    );
    $form['markup_16'] = array(
      '#markup' => '<br><div class="mo_saml_highlight_background_note_2" style="width:35% !important;">Please login with your miniorange account.</b></div><br>',
    );
    $form['Mo_auth_customer_login_username'] = array(
      '#type' => 'email',
      '#title' => t('Email <span style="color: red">*</span>'),
      '#attributes' => array(
        'style' => 'width:50%',
      ),
    );
    $form['Mo_auth_customer_login_password'] = array(
      '#type' => 'password',
      '#title' => t('Password <span style="color: red">*</span>'),
      '#attributes' => array(
        'style' => 'width:50%',
      ),
    );
    $form['Mo_auth_customer_login_button'] = array(
      '#type' => 'submit',
      '#value' => t('Login'),
      '#limit_validation_errors' => array(),
      '#prefix' => '<br><div class="ns_row"><div class="ns_name">',
      '#suffix' => '</div>',
    );
    $form['register_link'] = array(
      '#markup' => '<a href="' . $url . '" class="ns_display"><b>Create an account?</b></a>',
      '#prefix' => '<div class="ns_value">',
      '#suffix' => '</div></div><br></div>',
    );
  }
  MoAuthUtilities::AddsupportTab($form, $form_state);
  return $form;
}