From 6ae21577802462f38d98dd0e5415166008b1b13f Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Wed, 27 Apr 2022 12:48:26 -0400 Subject: Started work on user-facing user stuff for web interface. --- captain/db.f90 | 21 +++++++++++++++++++++ captain/templates/forgot.html | 11 +++++++++++ captain/templates/index.html | 3 ++- captain/templates/login.html | 20 ++++++++++++++++++++ captain/templates/profile.html | 6 ++++++ captain/web.f90 | 18 ++++++++++++++++-- 6 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 captain/templates/forgot.html create mode 100644 captain/templates/login.html create mode 100644 captain/templates/profile.html diff --git a/captain/db.f90 b/captain/db.f90 index 77e12ed..7a8052d 100644 --- a/captain/db.f90 +++ b/captain/db.f90 @@ -1543,5 +1543,26 @@ contains end if end function get_session_auth_db + + subroutine get_session_username_db(session, username) + implicit none + + character(len=*), intent(in)::session + character(len=*), intent(out)::username + + type(sqlite3_stmt)::stmt + + username = ' ' + + if(stmt%prepare(db, "SELECT username FROM session_auth WHERE session=? LIMIT 1") == SQLITE_OK) then + if(stmt%bind_text(1, session) == SQLITE_OK) then + if(stmt%step() == SQLITE_ROW) then + call stmt%column_text(0, username) + end if + end if + call stmt%finalize() + end if + + end subroutine get_session_username_db end module captain_db diff --git a/captain/templates/forgot.html b/captain/templates/forgot.html new file mode 100644 index 0000000..595cf9e --- /dev/null +++ b/captain/templates/forgot.html @@ -0,0 +1,11 @@ +{% extends index.html as contents %} + +

Forgot Your Password?

+ +

Please enter the email address associated with the account below:

+ +
+ + + +
diff --git a/captain/templates/index.html b/captain/templates/index.html index fc4de13..9f7b0ec 100644 --- a/captain/templates/index.html +++ b/captain/templates/index.html @@ -18,6 +18,7 @@
  • Instructions
  • Groups
  • About
  • +
  • {{ user_link_text }}
  • {{ title }} - I'm Levitating!

    @@ -30,7 +31,7 @@
    -

    Copyright © 2021 Approximatrix, LLC

    +

    Copyright © 2022 Approximatrix, LLC

    diff --git a/captain/templates/login.html b/captain/templates/login.html new file mode 100644 index 0000000..ab06b26 --- /dev/null +++ b/captain/templates/login.html @@ -0,0 +1,20 @@ +{% extends index.html as contents %} + +

    User Login for the {{ project }} Project

    + +
    +
    + Existing Users +

    + +

    +

    + +

    + +
    +
    + +

    {{ login_message }}

    + +

    Forgot Password?

    diff --git a/captain/templates/profile.html b/captain/templates/profile.html new file mode 100644 index 0000000..c0738c9 --- /dev/null +++ b/captain/templates/profile.html @@ -0,0 +1,6 @@ +{% extends index.html as contents %} + +

    User Profile - {{ username }}

    + +

    Logout

    + diff --git a/captain/web.f90 b/captain/web.f90 index f66250c..09d687b 100644 --- a/captain/web.f90 +++ b/captain/web.f90 @@ -899,7 +899,7 @@ 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 captain_db, only: scan_instructions_for_db + use captain_db, only: scan_instructions_for_db, get_session_auth_db, get_session_username_db use utilities, only: build_date implicit none @@ -912,7 +912,7 @@ contains character(64)::first character(len=:), pointer::contents - character(128)::job_page_title + character(128)::job_page_title, username integer::i @@ -1029,6 +1029,20 @@ contains 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 write_log("Rendering page for "//req%location) call page%render() -- cgit v1.2.3