aboutsummaryrefslogtreecommitdiff
path: root/captain/web.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-05-12 09:19:59 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-05-12 09:19:59 -0400
commit738833d70c8d6cca3bbf9efe0c8dd24ed0395dde (patch)
tree2b7a565b3a9753f9aa78defcbe2ba57805d51ee7 /captain/web.f90
parenta213818a689e41df697d1b2baf6864fc62859fdb (diff)
downloadlevitating-738833d70c8d6cca3bbf9efe0c8dd24ed0395dde.tar.gz
levitating-738833d70c8d6cca3bbf9efe0c8dd24ed0395dde.zip
Added post handling to the captain. Improved the query utilities for extracting values from a query string. Added a redirect template for html.
Diffstat (limited to 'captain/web.f90')
-rw-r--r--captain/web.f9045
1 files changed, 45 insertions, 0 deletions
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