Login_Action::STOP_LOGIN_PROCESS, 'log_in_with_totp_code' => Login_Action::LOG_IN_WITH_TOTP_CODE, 'log_in_with_backup_code' => Login_Action::LOG_IN_WITH_BACKUP_CODE, 'log_in_with_sms_code' => Login_Action::LOG_IN_WITH_SMS_CODE, 'log_in_with_call_code' => Login_Action::LOG_IN_WITH_CALL_CODE, 'verify_totp_code' => Login_Action::VERIFY_TOTP_CODE, 'verify_backup_code' => Login_Action::VERIFY_BACKUP_CODE, 'verify_sms_code' => Login_Action::VERIFY_SMS_CODE, 'verify_call_code' => Login_Action::VERIFY_CALL_CODE, 'open_sms_auth' => Login_Action::OPEN_NEW_SMS_AUTHENTICATION, 'open_call_auth' => Login_Action::OPEN_NEW_CALL_AUTHENTICATION, 'configure' => Login_Action::CONFIGURE, 'confirm_totp' => Login_Action::TOTP_CONFIRMATION, 'reset_totp' => Login_Action::TOTP_RESET, ); /** * @param Login_Support $login_support * @param Second_Factor_Template_Picker $template_picker * @param Request $request * @param Login_Response $login_response * @param OAuth_Storage $oauth_storage * @param Session $session */ public function __construct( Login_Support $login_support, Second_Factor_Template_Picker $template_picker, Request $request, Login_Response $login_response, OAuth_Storage $oauth_storage, Session $session ) { parent::__construct( $login_support ); $this->template_picker = $template_picker; $this->request = $request; $this->login_response = $login_response; $this->oauth_storage = $oauth_storage; $this->session = $session; } /** * @param null|WP_Error|WP_User $user * * @return bool */ public function supports( $user ) { $final_response = $this->login_support->get_final_response(); if ( $final_response instanceof JSON_Response ) { return false; } if ( $this->is_wp_user( $user ) ) { return true; } try { $this->get_wp_user(); return true; } catch ( User_Not_Found_Exception $e ) { return false; } } /** * @param null|WP_Error|WP_User $user * * @return bool|JSON_Response|Redirection_Response|View_Response */ protected function handle( $user ) { try { $integration_user = $this->get_integration_user(); if ( is_null( $integration_user ) ) { $response = $this->json_error( Errors::INTEGRATION_USER_ERROR, 404 ); $this->login_support->set_final_response( $response ); return $this->fallback( $user ); } $final_response = $this->login_support->get_final_response(); if ( ! $final_response instanceof View_Response ) { $template = $this->template_picker->get_template( $this->request, $integration_user ); } else { foreach ( $final_response->get_data() as $variable_name => $variable_value ) { $this->login_response->set( $variable_name, $variable_value ); } $template = $final_response->get_template(); } $this->login_response->set_from_request( $this->request ); $this->login_response->set_from_integration_user( $integration_user ); $this->login_response->set_from_storage( $this->user_storage ); $this->login_response->set( 'error', $this->login_support->get_wp_error() ); if ( $integration_user->hasMobileUser() ) { $integration_id = $this->oauth_storage->get_integration_id(); $this->login_response->set( 'integration_id', $integration_id ); $session_id = $this->session->get( Authenticate_Filter::PUSHER_SESSION_ID_KEY ); $this->login_response->set( Authenticate_Filter::PUSHER_SESSION_ID_KEY, $session_id ); } $this->login_response->set( 'actions', $this->login_actions ); $data = $this->login_response->get_all(); if ( array_key_exists( 'redirect_to', $data ) ) { $redirect_to = $data['redirect_to']; if ( $this->login_support->secure_cookie() && false !== strpos( $redirect_to, 'wp-admin' ) ) { $redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to ); $data['redirect_to'] = $redirect_to; } } return $this->view( $template, $data ); } catch ( Exception $e ) { $this->capture_exception( $e ); } return $this->fallback( $user ); } }