fix: fix logout flow which wasn't being triggered, remove useless html code
This commit is contained in:
parent
efac1cc33c
commit
3186afe96d
11 changed files with 34 additions and 118 deletions
|
|
@ -21,4 +21,4 @@ version: 0.2.4
|
|||
# incremented each time you make changes to the application. Versions are not expected to
|
||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||
# It is recommended to use it with quotes.
|
||||
appVersion: "0.2.4"
|
||||
appVersion: "0.2.5"
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ image:
|
|||
# This sets the pull policy for images.
|
||||
pullPolicy: Always
|
||||
# Overrides the image tag whose default is the chart appVersion.
|
||||
tag: "0.2.4"
|
||||
tag: "0.2.5"
|
||||
|
||||
# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
|
||||
imagePullSecrets: []
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "huesoporro"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
description = "Misc Twitch bots"
|
||||
readme = "README.md"
|
||||
authors = [
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class ManageBotDTO(BaseModel):
|
|||
"/tts",
|
||||
media_type=MediaType.HTML,
|
||||
)
|
||||
async def get_tts_overlay() -> Template:
|
||||
async def get_tts_overlay(user: User) -> Template:
|
||||
return Template(template_name="tts.html")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,36 +7,3 @@ function getWebsocketProtocol() {
|
|||
return "wss://";
|
||||
}
|
||||
}
|
||||
|
||||
function addLogoutEvent() {
|
||||
const logoutButton = document.getElementById("logoutButton");
|
||||
logoutButton.addEventListener("click", () => {
|
||||
document.cookie = "twitchLoginData=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
||||
window.location.href = "/";
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function setCookie(name, value, days) {
|
||||
const date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
const expires = `expires=${date.toUTCString()}`;
|
||||
document.cookie = `${name}=${value};${expires};path=/;SameSite=Strict`;
|
||||
}
|
||||
|
||||
function getCookie(name) {
|
||||
const cookieName = `${name}=`;
|
||||
const decodedCookie = decodeURIComponent(document.cookie);
|
||||
const cookieArray = decodedCookie.split(';');
|
||||
|
||||
for (let i = 0; i < cookieArray.length; i++) {
|
||||
let cookie = cookieArray[i];
|
||||
while (cookie.charAt(0) === ' ') {
|
||||
cookie = cookie.substring(1);
|
||||
}
|
||||
if (cookie.indexOf(cookieName) === 0) {
|
||||
return cookie.substring(cookieName.length, cookie.length);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@
|
|||
<nav>
|
||||
<ul>
|
||||
<li>Chatbot</li>
|
||||
<li><a href="/tts">TTS</a></li>
|
||||
<li><a href="/lefunny">Le Funny</a></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
|
||||
<li><a href="#" disabled>TTS</a></li>
|
||||
<li><a href="#" disabled="true">Le Funny</a></li>
|
||||
</ul>
|
||||
{% include 'logout.html' %}
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
|
|
@ -178,7 +176,7 @@
|
|||
})
|
||||
const data = await response.json()
|
||||
console.log(data);
|
||||
if (response.ok){
|
||||
if (response.ok) {
|
||||
alert("Settings saved successfully")
|
||||
}
|
||||
}
|
||||
|
|
@ -186,8 +184,6 @@
|
|||
|
||||
const chatbotManager = new ChatbotManager();
|
||||
chatbotManager.setEvents();
|
||||
|
||||
addLogoutEvent()
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
<main>
|
||||
<section>
|
||||
<form>
|
||||
<a role="button" href="{{ twitch_login_url }}" id="loginButton" type="button" style="background-color: #B645CD; border-color: #B645CD">Login
|
||||
<a role="button" href="{{ twitch_login_url }}" id="loginButton" type="button"
|
||||
style="background-color: #B645CD; border-color: #B645CD">Login
|
||||
with
|
||||
Twitch
|
||||
</a>
|
||||
|
|
@ -14,66 +15,7 @@
|
|||
</section>
|
||||
</main>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
class LoginManager {
|
||||
constructor() {
|
||||
this.loginData = null;
|
||||
}
|
||||
|
||||
async readLoginData() {
|
||||
const loginData = getCookie("twitchLoginData");
|
||||
|
||||
try {
|
||||
this.loginData = loginData ? JSON.parse(loginData) : null;
|
||||
return this.loginData;
|
||||
} catch (error) {
|
||||
console.error("Error reading login data:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
// Check if access_token is present in the URL hash
|
||||
const hashParams = new URLSearchParams(window.location.hash.substring(1));
|
||||
const accessToken = hashParams.get('access_token');
|
||||
|
||||
if (accessToken) {
|
||||
const loginData = {
|
||||
access_token: accessToken,
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
|
||||
try {
|
||||
setCookie("twitchLoginData", JSON.stringify(loginData), 30);
|
||||
this.loginData = loginData;
|
||||
|
||||
const loginButton = document.getElementById("loginButton");
|
||||
if (loginButton) {
|
||||
loginButton.style.display = 'none';
|
||||
}
|
||||
|
||||
history.replaceState(null, document.title, window.location.pathname);
|
||||
|
||||
window.location.href = '/';
|
||||
} catch (error) {
|
||||
console.error("Error saving login data:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const loginManager = new LoginManager();
|
||||
|
||||
loginManager.readLoginData().then(loginData => {
|
||||
const loginButton = document.getElementById("loginButton");
|
||||
|
||||
if (loginData) {
|
||||
window.location.href = '/';
|
||||
} else {
|
||||
loginManager.saveSettings();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
|
|
|||
13
src/huesoporro/templates/logout.html
Normal file
13
src/huesoporro/templates/logout.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<ul>
|
||||
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
|
||||
</ul>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const logoutButton = document.getElementById("logoutButton");
|
||||
logoutButton.addEventListener("click", () => {
|
||||
console.log("Logging out...");
|
||||
document.cookie = "huesoporroAuth=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
||||
window.location.href = "/";
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
@ -1,17 +1,14 @@
|
|||
|
||||
{% include 'header.html' %}
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="/">Chatbot</a> </li>
|
||||
<li><a href="/">Chatbot</a></li>
|
||||
<li><a href="/tts">TTS</a></li>
|
||||
<li>Le Funny</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
|
||||
</ul>
|
||||
{% include 'logout.html' %}
|
||||
</nav>
|
||||
<h1>Huesoporro🦴🍃</h1>
|
||||
</header>
|
||||
|
|
@ -20,14 +17,18 @@
|
|||
<table>
|
||||
<thead style="background-color: white; color: black">
|
||||
<tr>
|
||||
<th >Sentence</th>
|
||||
<th>Sentence</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for sentence in sentences %}
|
||||
<tr>
|
||||
<td>{{ sentence.sentence }}</td>
|
||||
<td><button id="delete-{{ sentence.id }}" style="border-color: #aa0000; background-color: #aa0000">Delete</button></td>
|
||||
<td>
|
||||
<button id="delete-{{ sentence.id }}" style="border-color: #aa0000; background-color: #aa0000">
|
||||
Delete
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@
|
|||
<li>TTS</li>
|
||||
<li><a href="/lefunny">Le Funny</a></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a id="logoutButton" href="#" style="color: #aa0000;">Logout</a></li>
|
||||
</ul>
|
||||
|
||||
{% include 'logout.html' %}
|
||||
</nav>
|
||||
<h1>Huesoporro🦴🍃</h1>
|
||||
</header>
|
||||
|
|
@ -186,7 +183,7 @@
|
|||
// generate <ur>/tts/permalink?access_token=<access_token>
|
||||
// the access token is available in the twitchLoginData cookie
|
||||
|
||||
const cookie = JSON.parse(getCookie("twitchLoginData"))
|
||||
const cookie = JSON.parse(getCookie("huesoporroAuth"))
|
||||
const permalinkUrl = `${window.location.origin}/tts/permalink?access_token=${cookie.access_token}`;
|
||||
navigator.clipboard.writeText(permalinkUrl);
|
||||
alert('OBS link copied to clipboard ' + permalinkUrl);
|
||||
|
|
|
|||
2
uv.lock
generated
2
uv.lock
generated
|
|
@ -460,7 +460,7 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "huesoporro"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "aiosqlite" },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue