function handle_page_four_submit in Google Authenticator / 2 Factor Authentication - 2FA 7
1 call to handle_page_four_submit()
File
- ./
mo_auth_inline_registration.inc, line 684
Code
function handle_page_four_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
$method = $form_state['storage']['page_three_values']['mo_auth_method'];
if (AuthenticationType::isCodeBelongsToAAuthenticator($method)) {
$email = $form_state['storage']['page_one_values']['mo_auth_user_email'];
$google_auth_response = $form_state['storage']['page_four_values']['google_auth_response'];
$token = $form['mo_auth_googleauth_token']['#value'];
$secret = $google_auth_response->secret;
$customer = new MiniorangeCustomerProfile();
$miniorange_user = new MiniorangeUser($customer
->getCustomerID(), $email, NULL, NULL, AuthenticationType::$GOOGLE_AUTHENTICATOR['code']);
$auth_api_handler = new AuthenticationAPIHandler($customer
->getCustomerID(), $customer
->getAPIKey());
$response = $auth_api_handler
->register($miniorange_user, AuthenticationType::$GOOGLE_AUTHENTICATOR['code'], $secret, $token, NULL);
if ($response->status == 'SUCCESS') {
$form_state['storage']['page_five'] = TRUE;
$form_state['storage']['page_four_values'] = $form_state['values'];
return;
}
elseif ($response->status == 'FAILED') {
// Passcode incorrect. Try again - Show error form
form_set_error('user_registration', 'The passcode you have entered is incorrect.');
$error_form = mo_auth_get_google_authentication_form($form_state, FALSE);
$form_state['complete form']['mo_auth_googleauth_token'] = $error_form['mo_auth_googleauth_token'];
return;
}
}
elseif ($method == AuthenticationType::$QR_CODE['code'] || $method == AuthenticationType::$SOFT_TOKEN['code'] || $method == AuthenticationType::$PUSH_NOTIFICATIONS['code']) {
$qrcode_response = $form_state['storage']['page_four_values']['qrcode_response'];
$customer = new MiniorangeCustomerProfile();
$auth_api_handler = new AuthenticationAPIHandler($customer
->getCustomerID(), $customer
->getAPIKey());
$response = $auth_api_handler
->getRegistrationStatus($qrcode_response->txId);
if ($response->status == 'SUCCESS') {
$form_state['storage']['page_five'] = TRUE;
return;
}
}
elseif ($method == AuthenticationType::$SMS['code'] || $method == AuthenticationType::$SMS_AND_EMAIL['code'] || $method == AuthenticationType::$OTP_OVER_PHONE['code'] || $method == AuthenticationType::$OTP_OVER_EMAIL['code']) {
global $base_url;
$phone = $form_state['input']['mo_auth_otpoversms_phone'];
$email = $form_state['storage']['page_one_values']['mo_auth_user_email'];
$customer = new MiniorangeCustomerProfile();
if ($method == AuthenticationType::$SMS_AND_EMAIL['code']) {
$miniorange_user = new MiniorangeUser($customer
->getCustomerID(), NULL, $phone, NULL, $method, $email);
}
elseif ($method == AuthenticationType::$SMS['code'] || $method == AuthenticationType::$OTP_OVER_PHONE['code']) {
$miniorange_user = new MiniorangeUser($customer
->getCustomerID(), NULL, $phone, NULL, $method, NULL);
}
elseif ($method == AuthenticationType::$OTP_OVER_EMAIL['code']) {
$miniorange_user = new MiniorangeUser($customer
->getCustomerID(), NULL, NULL, NULL, $method, $email);
}
$auth_api_handler = new AuthenticationAPIHandler($customer
->getCustomerID(), $customer
->getAPIKey());
$response = $auth_api_handler
->challenge($miniorange_user);
if ($response->status == 'SUCCESS') {
$form_state['storage']['page_otp_validate'] = TRUE;
$form_state['storage']['page_four_values'] = $form_state['values'];
$form_state['storage']['page_four_values']['user_challenge_response'] = $response;
return;
}
elseif ($response->status == 'FAILED') {
$error = $response->message;
/* If transactions limit exceeded return to the same form */
if ($error == 'The phone verification transaction limit has been exceeded. Please upgrade your premium plan.') {
form_set_error('form', t('Something went wrong. Please contact your administrator.'));
drupal_goto('user');
exit;
}
form_set_error('error_sending_otp', $error);
$form_state['storage']['error_code'] = 'INVALID_OTP';
$error_form = mo_auth_get_otp_over_sms_validate_form($form_state, FALSE, $error);
$form_state['complete form']['mo_auth_otpoversms_code']['#prefix'] = $error_form['mo_auth_otpoversms_code']['#prefix'];
$form_state["rebuild"] = TRUE;
return;
}
}
elseif ($method == AuthenticationType::$KBA['code']) {
handle_page_five_submit($form, $form_state);
return;
}
// Handle all error
}