authenticator = $authenticator; $this->authentication_storage = $storage->get_authentication_storage(); $this->user_storage = $storage->get_user_storage(); $this->integration_user = $integration_user; $this->error_handler = $error_handler; } /** * @param WP_Error|WP_User $user * @param JSON_Response|View_Response|null $response * * @return JSON_Response|View_Response|Redirect_Response|null */ public function handle( $user, $response = null ) { try { if ( $response instanceof JSON_Response || ! $this->user_storage->is_wp_user_set() ) { return $this->run_next( $user, $response ); } if ( ! $this->integration_user->exists() ) { $response = $this->json_error( Notification::get( 'integration-user-not-found' ), 404 ); return $this->run_next( $user, $response ); } if ( ! $response instanceof View_Response ) { $this->authenticator->open_authentication( $this->integration_user->get_user(), $this->is_wp_user( $user ) ); } } catch ( Authentication_Limit_Reached_Exception $e ) { $this->user_storage->block_user(); $this->authentication_storage->close_authentication( $this->user_storage->get_user_id() ); $response = $this->json_error( Notification::get( 'authentication-limit' ), 403 ); } catch ( Exception $e ) { $response = $this->error_handler->capture_exception( $e )->to_json( $e ); } return $this->run_next( $user, $response ); } }