public function MoAuthCustomerSetup::buildForm in Google Authenticator / 2 Factor Authentication - 2FA 8.2
Same name and namespace in other branches
- 8 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 30 - Contains form for customer setup.
Class
- MoAuthCustomerSetup
- Customer setup form().
Namespace
Drupal\miniorange_2fa\FormCode
public function buildForm(array $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' => array(
'miniorange_2fa/miniorange_2fa.license',
"miniorange_2fa/miniorange_2fa.admin",
),
),
);
if ($current_status == 'VALIDATE_OTP') {
$form['markup_top_2'] = array(
'#markup' => '<div class="mo_2fa_table_layout_1"><div class="mo_2fa_table_layout mo_2fa_container">',
);
/**
* Create container to hold @Login form elements.
*/
$form['mo_login_form'] = array(
'#type' => 'fieldset',
'#title' => t('Verify OTP'),
'#attributes' => array(
'style' => 'padding:2% 2% 30% 2%; margin-bottom:2%',
),
);
$form['mo_login_form']['mo_auth_customer_otp_token'] = array(
'#type' => 'textfield',
'#title' => t('Please enter the OTP you received'),
'#attributes' => array(
'autofocus' => 'true',
),
'#required' => TRUE,
'#description' => '<strong>' . t('Note:') . '</strong> ' . t('We have sent an OTP to') . ' <strong><em>' . \Drupal::config('miniorange_2fa.settings')
->get('mo_auth_customer_admin_email') . '</em></strong>. ',
t('Please enter the OTP to verify your email.'),
'#maxlength' => 8,
'#prefix' => '<br><hr><br>',
'#suffix' => '<br>',
);
$form['mo_login_form']['mo_auth_customer_validate_otp_button'] = array(
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => t('Validate OTP'),
'#submit' => array(
'::mo_auth_validate_otp_submit',
),
);
$form['mo_login_form']['Mo_auth_customer_setup_resendotp'] = array(
'#type' => 'submit',
'#value' => t('Resend OTP'),
'#limit_validation_errors' => array(),
'#submit' => array(
'::mo_auth_resend_otp',
),
);
$form['mo_login_form']['Mo_auth_customer_setup_back'] = array(
'#type' => 'submit',
'#button_type' => 'danger',
'#value' => t('Back'),
'#limit_validation_errors' => array(),
'#submit' => array(
'::mo_auth_back',
),
);
$form['mo_login_form']['main_layout_div_end'] = array(
'#markup' => '<br></div>',
);
MoAuthUtilities::miniOrange_advertise_network_security($form, $form_state);
return $form;
}
elseif ($current_status == 'PLUGIN_CONFIGURATION') {
$utilities = new MoAuthUtilities();
$custom_attribute = $utilities::get_users_custom_attribute($user_id);
$user_email = isset($custom_attribute[0]) && is_object($custom_attribute[0]) ? $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(is_object($response) && $response->status != 'FAILED' ? $response->authType : '-');
$variables_and_values = array(
//
'mo_user_limit_exceed',
'mo_auth_customer_admin_email',
'mo_auth_customer_id',
'mo_auth_customer_api_key',
'mo_auth_customer_token_key',
'mo_auth_customer_app_secret',
'mo_auth_2fa_license_type',
'mo_auth_2fa_license_plan',
'mo_auth_2fa_license_no_of_users',
'mo_auth_2fa_ivr_remaining',
'mo_auth_2fa_sms_remaining',
'mo_auth_2fa_email_remaining',
'mo_auth_2fa_license_expiry',
'mo_auth_2fa_support_expiry',
);
$mo_db_values = $utilities
->miniOrange_set_get_configurations($variables_and_values, 'GET');
$form['markup_top_1'] = array(
'#markup' => '<div class="mo_2fa_table_layout_1"><div id="Register_Section" class="mo_2fa_table_layout mo_2fa_container">',
);
/** Show message if user creation limit exceeded */
$mo_user_limit = $mo_db_values['mo_user_limit_exceed'];
if (isset($mo_user_limit) && $mo_user_limit == TRUE) {
$form['markup_top_2'] = array(
'#markup' => '<div class="users_2fa_limit_exceeded_message">' . t('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_2fa_welcome_message">' . t('Thank you for registering with miniOrange') . '</div>',
);
$form['mo_profile_information'] = array(
'#type' => 'details',
'#title' => t('Profile Details'),
'#attributes' => array(
'style' => 'margin-bottom:2%;',
),
);
$mo_table_content = array(
array(
'2 Factor Registered Email',
$mo_db_values['mo_auth_customer_admin_email'],
),
array(
'Activated 2nd Factor',
$authType['name'],
),
array(
'Xecurify Registered Email',
$user_email,
),
array(
'Customer ID',
$mo_db_values['mo_auth_customer_id'],
),
array(
'API Key',
$mo_db_values['mo_auth_customer_api_key'],
),
array(
'Token Key',
$mo_db_values['mo_auth_customer_token_key'],
),
array(
'App Secret',
$mo_db_values['mo_auth_customer_app_secret'],
),
);
$form['mo_profile_information']['miniorange_testing_form_element'] = array(
'#type' => 'table',
'#header' => array(
'ATTRIBUTE',
'VALUE',
),
'#rows' => $mo_table_content,
'#empty' => t('Something is not right. Please run the update script or contact us at') . '<a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a>',
'#responsive' => TRUE,
'#sticky' => FALSE,
//headers will move with the scroll
'#size' => 2,
);
$form['mo_profile_information']['miniorange_customer_Remove_Account_info'] = array(
'#markup' => '<br/><h3>Remove Account:</h3><p>This section will help you to remove your current logged in account without losing your current configurations.</p>',
);
$form['mo_profile_information']['miniorage_remove_account'] = array(
'#type' => 'link',
'#title' => $this
->t('Remove Account'),
'#url' => Url::fromRoute('miniorange_2fa.modal_form'),
'#attributes' => [
'class' => [
'use-ajax',
'button',
],
],
'#suffix' => '<br/><br/>',
);
$form['mo_license_information'] = array(
'#type' => 'fieldset',
'#title' => t('License info'),
'#attributes' => array(
'style' => 'padding:2% 2%; margin-bottom:7%',
),
);
$isLicenseExpired = MoAuthUtilities::getIsLicenseExpired($mo_db_values['mo_auth_2fa_license_expiry']);
$NoofUsers = [
'data' => Markup::create('</span><a target="_blank" href=" ' . MoAuthUtilities::getUpgradeURL(MoAuthConstants::$ADD_USER_PLAN) . ' ">ADD MORE USERS</a>'),
];
$updateLicense = '';
if ($isLicenseExpired['LicenseGoingToExpire']) {
$updateLicense = [
'data' => Markup::create('</span><a target="_blank" href=" ' . MoAuthUtilities::getUpgradeURL(MoAuthConstants::$RENEW_SUBSCRIPTION_PLAN) . ' ">RENEW LICENSE & SUPPORT</a>'),
];
}
$mo_license_table_content = array(
array(
'License Type',
$mo_db_values['mo_auth_2fa_license_type'],
'',
),
array(
'License Plan',
$mo_db_values['mo_auth_2fa_license_plan'],
'',
),
array(
'No. of Users',
$mo_db_values['mo_auth_2fa_license_no_of_users'],
$NoofUsers,
),
);
$mo_license_table_content_2 = array(
array(
'IVR Transactions Remaining',
$mo_db_values['mo_auth_2fa_ivr_remaining'],
'',
),
array(
'SMS Transactions Remaining',
$mo_db_values['mo_auth_2fa_sms_remaining'],
'',
),
array(
'Email Transactions Remaining',
$mo_db_values['mo_auth_2fa_email_remaining'],
'',
),
array(
'License Expiry',
$mo_db_values['mo_auth_2fa_license_expiry'],
$updateLicense,
),
array(
'Support Expiry',
$mo_db_values['mo_auth_2fa_support_expiry'],
'',
),
);
if ($mo_db_values['mo_auth_2fa_license_type'] !== 'DEMO') {
$mo_license_table_content = array_merge($mo_license_table_content, $mo_license_table_content_2);
}
$form['mo_license_information']['miniorange_hidden_value'] = array(
'#type' => 'hidden',
'#value' => 'User_Logged_in',
);
$form['mo_license_information']['miniorange_customer-license'] = array(
'#type' => 'table',
'#header' => array(
'ATTRIBUTE',
'VALUE',
'ACTION',
),
'#rows' => $mo_license_table_content,
'#empty' => t('Something is not right. Please run the update script or contact us at') . ' <a href="mailto:drupalsupport@xecurify.com">drupalsupport@xecurify.com</a>',
'#responsive' => TRUE,
'#sticky' => FALSE,
//headers will move with the scroll
'#size' => 2,
'#prefix' => '<br>',
'#suffix' => '<br>',
);
$form['mo_license_information']['fecth_customer_license'] = array(
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => t('Check License'),
'#submit' => array(
'::mo_auth_fetch_customer_license',
),
'#suffix' => '</div>',
);
MoAuthUtilities::miniOrange_advertise_network_security($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_2fa_table_layout_1"><div class="mo_2fa_table_layout mo_2fa_container">
',
);
if ($tab == 'register') {
/**
* Create container to hold @Register form elements.
*/
$form['mo_register_form'] = array(
'#type' => 'fieldset',
'#title' => t('Register/Login with miniOrange'),
'#attributes' => array(
'style' => 'padding:2%; margin-bottom:2%',
),
);
$form['mo_register_form']['markup_msg_1'] = array(
'#markup' => '<br><hr><br>
<div class="mo_2fa_highlight_background_note">' . t('Just complete the short registration below to configure this 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_register_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',
'style' => 'width:60%;',
),
);
$form['mo_register_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',
),
'style' => 'width:60%;',
),
);
$form['mo_register_form']['Mo_auth_customer_register_password'] = array(
'#type' => 'password_confirm',
);
$form['mo_register_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['mo_register_form']['already_account_link'] = array(
'#markup' => '<a href="' . $url . '/?tab=login" class="button button--primary"><b>' . t('Already have an account?') . '</b></a>',
'#prefix' => '<div class="ns_value">',
'#suffix' => '</div></div><br><br></div>',
);
}
else {
/**
* Create container to hold @Login form elements.
*/
$form['mo_login_form'] = array(
'#type' => 'fieldset',
'#title' => t('Login with miniOrange'),
'#attributes' => array(
'style' => 'padding:2% 2% 15% 2%; margin-bottom:2%',
),
);
$form['mo_login_form']['markup_16'] = array(
'#markup' => '<br><hr><br>
<div class="mo_2fa_highlight_background_note" style="width:35% !important;">' . t('Please login with your miniOrange account.') . '</br></div>',
);
$form['mo_login_form']['Mo_auth_customer_login_username'] = array(
'#type' => 'email',
'#title' => t('Email') . ' <span style="color: red">*</span>',
'#attributes' => array(
'style' => 'width:50%',
),
);
$form['mo_login_form']['Mo_auth_customer_login_password'] = array(
'#type' => 'password',
'#title' => t('Password') . ' <span style="color: red">*</span>',
'#attributes' => array(
'style' => 'width:50%',
),
);
$form['mo_login_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['mo_login_form']['register_link'] = array(
'#markup' => '<a href="' . $url . '" class="button button--primary"><b>' . t('Create an account?') . '</b></a>',
'#prefix' => '<div class="ns_value">',
'#suffix' => '</div></div><br></div>',
);
}
MoAuthUtilities::miniOrange_advertise_network_security($form, $form_state);
return $form;
}