From 9358dd39a1a264843a369fddfe493ae09962360c Mon Sep 17 00:00:00 2001 From: julien Date: Mon, 2 Nov 2026 17:20:48 +0100 Subject: [PATCH] Add login/logout --- netig.rb | 6 ++++++ public/css/style.css | 28 +++++++++++++++++++++++----- routes/admin.rb | 34 ++++++++++++++++++++++++++++++++++ views/admin.erb | 6 ++++++ views/layout.erb | 14 ++++++++++++-- 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 routes/admin.rb create mode 100644 views/admin.erb diff --git a/netig.rb b/netig.rb index f374b31..6f2c7e3 100644 --- a/netig.rb +++ b/netig.rb @@ -25,11 +25,17 @@ class Netig < Roda password_label "Mot de passe" login_button "Se connecter" + login_redirect "/temporary_page" + login_return_to_requested_location? true + already_logged_in do request.redirect("/") end + + logout_redirect "/" end + require_relative "routes/admin" require_relative "routes/contact" route do |r| diff --git a/public/css/style.css b/public/css/style.css index 83fc700..b66eba3 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -227,20 +227,38 @@ summary:focus-visible { color: var(--color-text); } +.topbar > form { + margin: 0 20px 0 auto; +} + .topbar a.topbar__account { margin-left: auto; margin-right: 20px; - padding: 8px 14px; - border: 1px solid var(--color-accent); - color: var(--color-accent); } -.topbar a.topbar__account:hover { +.topbar .topbar__account { + display: inline-block; + padding: 8px 14px; + border: 1px solid var(--color-accent); + background: transparent; + color: var(--color-accent); + font: inherit; + line-height: normal; + text-decoration: none; +} + +.topbar .topbar__account:hover { background: var(--color-accent); color: var(--color-background); text-decoration: none; } +.topbar button.topbar__account { + appearance: none; + border-radius: 0; + cursor: pointer; +} + .topbar img { display: block; width: 48px; @@ -554,4 +572,4 @@ footer { .box__link:hover { transform: none; } -} +} \ No newline at end of file diff --git a/routes/admin.rb b/routes/admin.rb new file mode 100644 index 0000000..f0418bf --- /dev/null +++ b/routes/admin.rb @@ -0,0 +1,34 @@ +class Netig + hash_branch "admin" do |r| + require_admin!(r) + + @page_title = "Admin — NETig" + @page_description = "Interface d'administration de NETig." + @canonical_url = "https://netig.net/admin" + + r.is do + r.get do + view "admin" + end + end + end + + private + + def require_admin!(r) + rodauth.require_account + + admin = DB[:members].where( + account_id: rodauth.account_id, + admin: true + ).get(:admin) + + return if admin + + r.halt [ + 403, + { "Content-Type" => "text/plain; charset=utf-8" }, + ["Accès interdit."] + ] + end +end diff --git a/views/admin.erb b/views/admin.erb new file mode 100644 index 0000000..d2e27db --- /dev/null +++ b/views/admin.erb @@ -0,0 +1,6 @@ +
+
+

Interface d'administration de NETig

+

Test

+
+
diff --git a/views/layout.erb b/views/layout.erb index c590395..11aabbf 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -1,4 +1,3 @@ - @@ -40,7 +39,18 @@ NETmail ↗ NETcloud ↗ NETgit ↗ - Mon espace ➜ + <% if rodauth.logged_in? %> +
+ <%== rodauth.csrf_tag(rodauth.logout_path) %> + +
+ <% else %> + + Connexion ➜ + + <% end %>