function miniorange_saml_validate_otp_submit in Google Authenticator / 2 Factor Authentication - 2FA 7
Same name in this branch
- 7 configure_otp_over_sms.inc \miniorange_saml_validate_otp_submit()
- 7 configure_otp_over_sms_and_email.inc \miniorange_saml_validate_otp_submit()
2 string references to 'miniorange_saml_validate_otp_submit'
File
- ./
configure_otp_over_sms_and_email.inc, line 157
Code
function miniorange_saml_validate_otp_submit($form, &$form_state) {
global $base_url, $user;
if (empty($form['miniorange_phone']['#value'])) {
drupal_set_message(t('Please enter phone number to proceed.'), 'warning');
return;
}
elseif (empty($form['miniorange_OTP']['#value'])) {
drupal_set_message(t('Please enter otp to proceed.'), 'warning');
return;
}
$customer = new MiniorangeCustomerProfile();
$cKey = $customer
->getCustomerID();
$customerApiKey = $customer
->getAPIKey();
$otpToken = $form['miniorange_OTP']['#value'];
$user = user_load($user->uid);
$user_email = $user->miniorange_registered_email[LANGUAGE_NONE][0]['value'];
$phone_number = $form['miniorange_phone']['#value'];
variable_set('mo_phone', $phone_number);
$transactionId = variable_get('mo_auth_tx_id');
$customer_config = new MiniorangeCustomerSetup($user_email, $phone_number, NULL, NULL);
$response = $customer_config
->validate_otp_token($transactionId, $otpToken, $cKey, $customerApiKey);
$otp_validation = json_decode($response);
$txId = $otp_validation->txId;
if ($otp_validation->status == 'FAILED') {
drupal_set_message(t("Validation Failed. Please enter the correct OTP."), 'error');
}
else {
if ($otp_validation->status == 'SUCCESS') {
$form_state['rebuild'] = TRUE;
$authTypeCode = AuthenticationType::$SMS_AND_EMAIL['code'];
global $base_url, $user;
$user = user_load($user->uid);
$user_email = $user->miniorange_registered_email[LANGUAGE_NONE][0]['value'];
$customer = new MiniorangeCustomerProfile();
$miniorange_user = new MiniorangeUser($customer
->getCustomerID(), $user_email, $phone_number, NULL, AuthenticationType::$SMS_AND_EMAIL['code']);
$auth_api_handler = new AuthenticationAPIHandler($customer
->getCustomerID(), $customer
->getAPIKey());
$configured_methods = mo_auth_get_configured_methods($user->uid);
if (!in_array(AuthenticationType::$SMS_AND_EMAIL['code'], $configured_methods)) {
array_push($user->configured_auth_methods[LANGUAGE_NONE], array(
'value' => AuthenticationType::$SMS_AND_EMAIL['code'],
));
}
$user_api_handler = new UsersAPIHandler($customer
->getCustomerID(), $customer
->getAPIKey());
// Updating the authentication method for the user
$miniorange_user
->setAuthType($authTypeCode);
$response = $user_api_handler
->update($miniorange_user);
if ($response->status == 'SUCCESS') {
user_save($user);
if ($authTypeCode == AuthenticationType::$SMS_AND_EMAIL['code']) {
drupal_set_message(t('OTP Over SMS and Email has been configured successfully.'), 'status');
}
drupal_goto('admin/config/people/mo_auth/setup');
}
return;
drupal_set_message(t('An error occured while processing your request. Please try again.'), 'error');
drupal_goto('admin/config/people/mo_auth/setup');
}
}
}