page = Views::BACKUP_AUTHENTICATION_PAGE; $this->code_checker = $code_checker; } /** * @inheritDoc */ public function supports( $user ): bool { if ( $this->is_wp_user( $user ) ) { return false; } return ! empty( $this->request->post( 'twofas_light_backup_code' ) ); } /** * @return JSON_Response|Not_Handled_Response|Redirect_Response|View_Response * * @throws Backup_Codes_Not_Found_Exception * @throws Invalid_Backup_Code_Exception */ protected function check_code() { $backup_code = new Backup_Code( $this->request->post( 'twofas_light_backup_code' ) ); $this->code_checker->check( $backup_code ); if ( ! $backup_code->accepted() ) { throw new Invalid_Backup_Code_Exception( 'Invalid backup code supplied' ); } Dispatcher::dispatch( new Backup_Login_Completed( $this->get_user_id(), $backup_code ) ); return $this->json( [ 'user_id' => $this->get_user_id() ], Code::OK ); } }