From e9460ea44fe7c11dc6d7d668ca9cd1b36418f097 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Thu, 24 Jun 2021 16:01:06 -0400 Subject: Player tokens can now be set via web interface. --- captain/db.f90 | 25 +++++++++++++++++++++++++ captain/web.f90 | 19 +++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/captain/db.f90 b/captain/db.f90 index b789280..315bd10 100644 --- a/captain/db.f90 +++ b/captain/db.f90 @@ -146,6 +146,31 @@ contains end subroutine update_player_token_db + function player_has_token_db(name) + implicit none + + character(*), intent(in)::name + logical::player_has_token_db + type(sqlite3_stmt)::stmt + + character(128)::tk + + player_has_token_db = .false. + + if(stmt%prepare(db, "SELECT token FROM players WHERE name=?") == SQLITE_OK) then + if(stmt%bind_text(1, name) == SQLITE_OK ) then + if(stmt%step() == SQLITE_ROW) then + call stmt%column_text(0, tk) + player_has_token_db = (trim(tk) /= "None") + end if + end if + end if + call stmt%finalize() + + + end function player_has_token_db + + subroutine remove_player_db(name) implicit none diff --git a/captain/web.f90 b/captain/web.f90 index c18848e..9817775 100644 --- a/captain/web.f90 +++ b/captain/web.f90 @@ -609,7 +609,17 @@ contains end if ! Token assignment - res = trim(res)//new_line(' ')//"

Security

"//new_line(' ')// & + res = trim(res)//new_line(' ')//"

Security

"//new_line(' ')//"

" + + if(player_has_token_db(trim(player_name))) then + res = trim(res)//"Player currently has a token assigned." + else + res = trim(res)//"Player is insecure! Please assign a token!" + end if + + res = trim(res)//"

" + + res = trim(res)//new_line(' ')// & '
'//new_line(' ')// & ''// & ''//new_line(' ')// & @@ -1016,7 +1026,7 @@ contains end function request_templated function handle_post(req) result(resp) - use captain_db, only: add_player_db, add_group_db + use captain_db, only: add_player_db, add_group_db, update_player_token_db use page_template use config, only: template_filepath use logging @@ -1055,6 +1065,11 @@ contains call add_player_db(posted%get_value("name")) call page%assign('destination', 'players.html') + else if(trim(second) == "assign_token.html") then + + call update_player_token_db(posted%get_value("player"), posted%get_value("token")) + call page%assign('destination', "players/"//posted%get_value("player")//".html") + end if else if(trim(category) == "groups") then -- cgit v1.2.3