function mo_auth_validate_otp_submit in Google Authenticator / 2 Factor Authentication - 2FA 7
Validate OTP.
1 string reference to 'mo_auth_validate_otp_submit'
- mo_auth_customer_setup in ./
mo_auth_customer_setup.inc - Customer setup form().
File
- ./
mo_auth_customer_setup.inc, line 245 - Contains form for customer setup.
Code
function mo_auth_validate_otp_submit(&$form, $form_state) {
global $user;
$user = user_load($user->uid);
$otp_token = trim($form['mo_auth_customer_otp_token']['#value']);
if (empty($otp_token)) {
drupal_set_message(t('The <b><u>OTP</u></b> field is mandatory.'), 'error');
return;
}
$username = variable_get('mo_auth_customer_admin_email', NULL);
$phone = variable_get('mo_auth_customer_admin_phone', NULL);
$txId = variable_get('mo_auth_tx_id', NULL);
$customerSetup = new MiniorangeCustomerSetup($username, $phone, NULL, $otp_token);
// Validate OTP.
$validate_otp_response = json_decode($customerSetup
->validate_otp_token($txId, $otp_token, MoAuthConstants::$DEFAULT_CUSTOMER_ID, MoAuthConstants::$DEFAULT_CUSTOMER_API_KEY));
if ($validate_otp_response->status == 'SUCCESS') {
// OTP Validated. Show Configuration page.
variable_del('mo_auth_tx_id');
// OTP Validated. Create customer.
$password = variable_get('mo_auth_customer_admin_password', '');
$customer_config = new MiniorangeCustomerSetup($username, $phone, $password, NULL);
$create_customer_response = $customer_config
->createCustomer();
if ($create_customer_response->status == 'SUCCESS') {
// Customer created.
mo_auth_save_customer($user, $create_customer_response, $username, $phone);
$current_status = 'PLUGIN_CONFIGURATION';
variable_set('mo_auth_status', $current_status);
drupal_set_message(t('Customer account created. Email Verification has been set as your default 2nd factor method.'));
drupal_goto('admin/config/people/mo_auth');
}
else {
if (trim($create_customer_response->message) == 'Email is not enterprise email.') {
variable_del('mo_auth_status');
drupal_set_message(t('There was an error creating an account for you.<br> You may have entered an invalid Email-Id
<strong>(We discourage the use of disposable emails) </strong>
<br>Please try again with a valid email.'), 'error');
}
else {
watchdog('miniorange_2fa', $create_customer_response->message);
variable_del('mo_auth_status');
drupal_set_message(t('An error occured while creating your account. Please try again or contact us at <a href="mailto:info@xecurify.com">info@xecurify.com</a>.'), 'error');
}
}
}
else {
drupal_set_message(t('The OTP you have entered is incorrect. Please try again.'), 'error');
}
}