api_wrapper = $api_wrapper; $this->error_handler = $error_handler; $this->user_factory = $user_factory; $this->user_storage = $user_storage; } /** * @return WP_User * * @throws User_Not_Found_Exception */ public function get_wp_user() { if ( $this->user_storage->is_wp_user_set() ) { return $this->user_storage->get_wp_user(); } $wp_user = $this->user_factory->create(); $this->user_storage->set_wp_user( $wp_user ); return $wp_user; } /** * @param int $user_id * * @return IntegrationUser|null * * @throws API_Exception */ public function get_integration_user( $user_id ) { if ( is_null( $this->integration_user ) ) { $this->integration_user = $this->api_wrapper->get_integration_user_by_external_id( $user_id ); } return $this->integration_user; } /** * @param JSON_Response|View_Response $response */ public function set_final_response( $response ) { $this->final_response = $response; } /** * @return null|JSON_Response|View_Response */ public function get_final_response() { return $this->final_response; } /** * @return bool */ public function has_final_response() { return ! is_null( $this->final_response ); } /** * @param int $user_id */ public function force_ssl_admin( $user_id ) { if ( ! force_ssl_admin() ) { if ( get_user_option( 'use_ssl', $user_id ) ) { $this->secure_cookie = true; force_ssl_admin( true ); } } } /** * @return bool */ public function secure_cookie() { return $this->secure_cookie; } /** * @param Exception $e */ public function capture_exception( Exception $e ) { $response = $this->error_handler->capture_exception( $e )->to_json( $e ); $this->set_final_response( $response ); } /** * @param string $error */ public function set_error( $error ) { $this->error = $error; } /** * @return string|WP_Error */ public function get_wp_error() { if ( empty( $this->error ) ) { return $this->error; } return new WP_Error( 'twofas_login_error', $this->error ); } /** * @return User_Storage */ public function get_user_storage() { return $this->user_storage; } }