aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2022-04-27 12:48:26 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2022-04-27 12:48:26 -0400
commit6ae21577802462f38d98dd0e5415166008b1b13f (patch)
tree8d8606f15fe24af885b67d0cf30279c64bcd9e3e
parente5a2850b6bb9887b241316be24b3f7047cef6ea3 (diff)
downloadlevitating-6ae21577802462f38d98dd0e5415166008b1b13f.tar.gz
levitating-6ae21577802462f38d98dd0e5415166008b1b13f.zip
Started work on user-facing user stuff for web interface.
-rw-r--r--captain/db.f9021
-rw-r--r--captain/templates/forgot.html11
-rw-r--r--captain/templates/index.html3
-rw-r--r--captain/templates/login.html20
-rw-r--r--captain/templates/profile.html6
-rw-r--r--captain/web.f9018
6 files changed, 76 insertions, 3 deletions
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 %}
+
+<h2>Forgot Your Password?</h2>
+
+<p>Please enter the email address associated with the account below:</p>
+
+<form id='login' action='{{ base_url }}/forgot.html' method='get' accept-charset='UTF-8' >
+ <label for="email">Email Address:</label>
+ <input type="text" name="email" id="email" />
+ <input type='submit' value="Reset" />
+</form>
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 @@
<li><a href="{{ base_url }}/instructions.html">Instructions</a></li>
<li><a href="{{ base_url }}/groups.html">Groups</a></li>
<li><a href="{{ base_url }}/about.html">About</a></li>
+ <li><a href="{{ base_url }}/{{ user_link_page }}.html">{{ user_link_text }}</a></li>
</ul>
</div>
<h1 style="overflow: hidden; text-overflow: ellipsis;white-space: nowrap;">{{ title }} - I'm Levitating!</h1>
@@ -30,7 +31,7 @@
</div>
<div class="footing">
- <p>Copyright &copy; 2021 Approximatrix, LLC</p>
+ <p>Copyright &copy; 2022 Approximatrix, LLC</p>
</div>
</body>
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 %}
+
+<h2>User Login for the {{ project }} Project</h2>
+
+<form style="text-align:center;" id='login' action='{{ base_url }}/login.html' method='post' accept-charset='UTF-8' >
+ <fieldset >
+ <legend>Existing Users</legend>
+ <p><label for='username' >User Name:</label>
+ <input type='text' name='username' id='username' maxlength="128"/>
+ </p>
+ <p><label for='password' >Password:</label>
+ <input type='password' name='password' id='password' maxlength="72"/>
+ </p>
+ <input type='submit' value="Login" />
+ </fieldset>
+</form>
+
+<p style="color: #f00; text-weight: 700;">{{ login_message }}</p>
+
+<p style="font-size: small;"><em><a href="{{ base_url }}/forgot.html">Forgot Password?</a></em></p>
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 %}
+
+<h2>User Profile - {{ username }}</h2>
+
+<p><strong><a href="{{ base_url }}/logout.html">Logout</a></strong></p>
+
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()