mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
feat(baserow): add one-time SSO warning JavaScript
- Introduced a generic sso_warning.js.j2 template under templates/roles/web-app/templates/javascripts/ - Included this template in web-app-baserow/templates/javascript.js.j2 - Added new variable js_application_name in roles/web-app-baserow/vars/main.yml to make the warning application-specific - Implemented cookie-based logic so the warning is only shown once per user (default: 365 days) Reference: https://chatgpt.com/share/68aecdae-82d0-800f-b05e-f2cb680664f1
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// Jinja2 variable for the application name
|
||||
const appName = "{{ js_application_name }}";
|
||||
const cookieName = appName + "SSONoticeShown";
|
||||
|
||||
// Function to set a cookie with expiration (in days)
|
||||
function setCookie(name, value, days) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + (days*24*60*60*1000));
|
||||
const expires = "expires="+ d.toUTCString();
|
||||
document.cookie = name + "=" + value + ";" + expires + ";path=/";
|
||||
}
|
||||
|
||||
// Function to read a cookie
|
||||
function getCookie(name) {
|
||||
const cname = name + "=";
|
||||
const decodedCookie = decodeURIComponent(document.cookie);
|
||||
const ca = decodedCookie.split(';');
|
||||
for(let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i].trim();
|
||||
if (c.indexOf(cname) === 0) {
|
||||
return c.substring(cname.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Main logic: show notice only once
|
||||
window.addEventListener("DOMContentLoaded", function() {
|
||||
if (!getCookie(cookieName)) {
|
||||
alert("Notice: " + appName + " is not integrated into the SSO. Login is not possible.");
|
||||
// Set cookie for 365 days
|
||||
setCookie(cookieName, "true", 365);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user