From 738833d70c8d6cca3bbf9efe0c8dd24ed0395dde Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Wed, 12 May 2021 09:19:59 -0400 Subject: Added post handling to the captain. Improved the query utilities for extracting values from a query string. Added a redirect template for html. --- captain/web.f90 | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'captain/web.f90') diff --git a/captain/web.f90 b/captain/web.f90 index 0f741d8..57f57f9 100644 --- a/captain/web.f90 +++ b/captain/web.f90 @@ -650,12 +650,57 @@ contains use server_response, only:request, response use http, only: HTTP_CODE_SUCCESS, HTTP_CODE_NOTFOUND use request_utils, only: get_job_page_title, handle_instruction_command + use http_post_utilities + use query_utilities, only: query implicit none type(request), intent(in)::req type(response)::resp + type(query)::posted + + character(1024)::template_file + type(template)::page + + character(64)::category, second + + posted = read_post_contents() + if(posted%component_count() > 0) then + + ! We will immediately redirect after the command is handled + call template_filepath("redirect.html", template_file) + call page%init(trim(template_file)) + + ! Handle based on category + call req%path_component(1, category) + if(trim(category) == "players") then + call req%path_component(2, second) + + ! Add a player + if(trim(second) == "add.html") then + + call add_player_db(posted%get_value("name")) + call page%assign('destination', 'players.html') + + end if + + end if + + ! Handle the template + call page%assign('base_url', req%server) + call page%render() + call write_log("Finalizing response", LOG_INFO) + resp%temporary_file = .true. + resp%body_filename => page%output_filename + resp%body_mimetype = "text/html" + + call posted%destroy() + + else + resp%code = 500 + + end if end function handle_post -- cgit v1.2.3