From b558fd94527e6a3f359c3ca766eeabaf0c7a8a57 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Thu, 28 Apr 2022 12:51:26 -0400 Subject: Sessions are now created and stored at login. --- captain/web.f90 | 68 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 18 deletions(-) (limited to 'captain/web.f90') diff --git a/captain/web.f90 b/captain/web.f90 index 09d687b..c3841c0 100644 --- a/captain/web.f90 +++ b/captain/web.f90 @@ -52,8 +52,45 @@ contains end function method + subroutine handle_basic_template_components(req, page) + use server_response + use page_template + use captain_db + use config + implicit none + + type(request), intent(in)::req + type(template), intent(inout)::page + character(len=128)::username + + call page%assign('project', project) + call page%assign('base_url', req%server) + + if(associated(req%token)) then + if(get_session_auth_db(req%token) > 0) then + + call page%assign('user_link_page', "profile") + call get_session_username_db(req%token, username) + call page%assign('user_link_text', trim(username)) + + else + + call page%assign('user_link_page', "login") + call page%assign('user_link_text', "Login") + + end if + else + + call page%assign('user_link_page', "login") + call page%assign('user_link_text', "Login") + + end if + + end subroutine handle_basic_template_components + subroutine build_request_object(req) use server_response, only:request + implicit none type(request), intent(out)::req character(len=:), allocatable::url, script_name @@ -1026,22 +1063,7 @@ contains end if - call page%assign('project', project) - call page%assign('base_url', req%server) - - if(associated(req%token)) then - if(get_session_auth_db(req%token) > 0) then - call page%assign('user_link_page', "profile") - call get_session_username_db(req%token, username) - call page%assign('user_link_text', trim(username)) - else - call page%assign('user_link_page', "login") - call page%assign('user_link_text', "Login") - end if - else - call page%assign('user_link_page', "login") - call page%assign('user_link_text', "Login") - end if + call handle_basic_template_components(req, page) call write_log("Rendering page for "//req%location) call page%render() @@ -1054,7 +1076,8 @@ contains end function request_templated function handle_post(req) result(resp) - use captain_db, only: add_player_db, add_group_db, update_player_token_db + use captain_db, only: add_player_db, add_group_db, update_player_token_db, create_user_session_db, & + validate_user_db use page_template use config, only: template_filepath use logging @@ -1111,11 +1134,20 @@ contains call page%assign('destination', 'groups.html') end if + + else if(trim(category) == "login.html") then + + ! Determine if logged in + if(validate_user_db(posted%get_value("username"), posted%get_value("password"))) then + call page%assign('destination', "home.html?token="//create_user_session_db(posted%get_value("username"))) + else + call page%assign('destination', "login.html?failed=1") + end if end if ! Handle the template - call page%assign('base_url', req%server) + call handle_basic_template_components(req, page) call page%render() call write_log("Finalizing response", LOG_INFO) -- cgit v1.2.3