authentication_storage = $storage->get_authentication_storage(); $this->user_storage = $storage->get_user_storage(); $this->options_storage = $storage->get_options(); $this->error_handler = $error_handler; } /** * @inheritDoc */ public function handle( $user, $response = null ) { if ( $response instanceof JSON_Response || ! $this->user_storage->is_wp_user_set() ) { return $this->run_next( $user, $response ); } try { $authentication = $this->authentication_storage->get_authentication( $this->user_storage->get_user_id() ); if ( ! $this->user_storage->is_totp_enabled() && ! $this->options_storage->has_obligatory_role($this->user_storage->get_roles())) { throw new Totp_Disabled_Exception(); } if ( is_null( $authentication ) ) { $authentication = $this->authentication_storage->open_authentication( $this->user_storage->get_user_id() ); } if ( $authentication->is_expired() ) { Dispatcher::dispatch( new Authentication_Expired( $authentication ) ); return $this->json_error( Notification::get( 'authentication-expired' ), Code::FORBIDDEN ); } if ( $authentication->is_rejected() ) { Dispatcher::dispatch( new Login_Attempts_Reached( $authentication ) ); return $this->json_error( Notification::get( 'authentication-limit' ), Code::FORBIDDEN ); } } catch ( Exception $e ) { $response = $this->error_handler->capture_exception( $e )->to_json( $e ); } return $this->run_next( $user, $response ); } }