Prepare dev instructure

This commit is contained in:
kbe
2025-08-16 09:00:38 +02:00
parent d96fb4be95
commit ed659c423e
15 changed files with 1434 additions and 27 deletions

View File

@@ -0,0 +1,9 @@
class PagesController < ApplicationController
# Display homepage
def home
end
# Display legal page
def legals
end
end

View File

@@ -0,0 +1,2 @@
module PagesHelper
end

View File

@@ -0,0 +1,55 @@
// app/javascript/controllers/logout_controller.js
import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
static values = {
url: String,
};
connect() {
// Optional: Add confirmation message
//console.log("Hello LogoutController, Stimulus!", this.element);
// this.element.dataset.confirm = "Êtes-vous sûr de vouloir vous déconnecter ?";
}
signOut(event) {
event.preventDefault();
console.log("LogoutController#signOut mounted");
// Ensure user wants to disconnect with a confirmation request
// if (this.hasUrlValue && !confirm(this.element.dataset.confirm)) { return; }
// Retrieve the csrf token from header
const csrfToken = document.querySelector("[name='csrf-token']").content;
// Define url to redirect user when action is valid
const url = this.hasUrlValue ? this.urlValue : this.element.href;
// Use fetch to send logout request
fetch(url, {
method: "DELETE",
headers: {
"X-CSRF-Token": csrfToken,
Accept: "application/json",
"Content-Type": "application/json",
},
credentials: "same-origin",
})
.then((response) => {
// console.log(this.element.dataset.loginUrlValue); // By default, we does not return anything.
// By default the response does not include any url.
// Redirect to default login page (loginUrlValue)
if (response.redirected) {
window.location.href = response.url;
} else if (this.element.dataset.loginUrlValue) {
window.location.href = this.element.dataset.loginUrlValue;
return;
}
window.location.href = "/";
})
.catch((error) => {
console.error("Error during sign out:", error);
});
}
}

View File

@@ -0,0 +1,2 @@
<h1>Pages#home</h1>
<p>Find me in app/views/pages/home.html.erb</p>

View File

@@ -0,0 +1,2 @@
<h1>Pages#legals</h1>
<p>Find me in app/views/pages/legals.html.erb</p>