Skip to content

Commit

Permalink
comments on login related files and signup fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jmort1021 committed Dec 13, 2024
1 parent ad342a2 commit b1b26bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions _includes/nav/home.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<style>
/* This style hides the authenticated content by default */
.header {
display: none;
}
</style>

<!-- The menu is guarded by class header, it is only displayed when user is authenticated -->
<div id="authenticatedContent" class="header">
<table>
<tr>
Expand All @@ -20,6 +22,11 @@
</div>

<script>
/**
* This script checks if the user is authenticated.
* If the user is authenticated, the 'header' class is removed from the authenticated content,
* making it visible.
*/
document.addEventListener('DOMContentLoaded', function() {
const isAuthenticated = localStorage.getItem('authenticated') === 'true';
if (isAuthenticated) {
Expand Down
3 changes: 3 additions & 0 deletions _includes/theme/minima/header.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- This fragment overrides the default header provided by the remote minima theme to add support for login functionality. -->
<header class="site-header">
<div class="wrapper">
{%- assign default_paths = site.pages | map: "path" -%}
Expand All @@ -16,6 +17,7 @@
</span>
</label>

<!-- Adding the page menus as defined in _config.yml, plus adding Login -->
<div class="trigger" data-baseurl="{{ site.baseurl }}">
{%- for path in site.header_pages -%}
{%- assign my_page = site.pages | where: "path", path | first -%}
Expand All @@ -30,4 +32,5 @@
</div>
</header>

<!-- Load login.js script to handle user authentication status -->
<script type="module" src="{{ site.baseurl }}/assets/js/api/login.js"></script>
15 changes: 15 additions & 0 deletions assets/js/api/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { pythonURI, fetchOptions } from './config.js';

console.log("login.js loaded");

/**
* This function is called when the DOM is loaded.
* It fetches the credentials from the API and updates the login area, based on the data.
* If the user is authenticated, the name of the user is shown as a link.
* If the user is not authenticated, a "Login" link is shown.
* The authenticated status is stored in the local storage.
* @param {string} baseurl - The base URL of the website.
*/
document.addEventListener('DOMContentLoaded', function() {
const baseurl = document.querySelector('.trigger').getAttribute('data-baseurl');
console.log("Base URL:", baseurl); // Debugging line
Expand All @@ -25,6 +33,13 @@ document.addEventListener('DOMContentLoaded', function() {
});
});

/**
* This function fetches the credentials of the User from the API.
* @param {string} baseurl - The base URL of the website.
* @returns {Promise} - The Promise object representing the completion of the function.
* @async - This function performs asynchronous operations using .then() and .catch() for handling responses.
* @function getCredentials
*/
function getCredentials(baseurl) {
const URL = pythonURI + '/api/id';
return fetch(URL, fetchOptions)
Expand Down
1 change: 0 additions & 1 deletion navigation/authentication/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ show_reading_time: false
name: document.getElementById("name").value,
uid: document.getElementById("signupUid").value,
password: document.getElementById("signupPassword").value,
kasm_server_needed: document.getElementById("kasmNeeded").checked,
}
};

Expand Down

0 comments on commit b1b26bc

Please sign in to comment.