Skip to content

Commit

Permalink
Add basic logout
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmauro committed Mar 13, 2024
1 parent 11b07a7 commit 78af329
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
39 changes: 39 additions & 0 deletions assets/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,14 @@ select {
inset: 0px;
}

.-inset-1 {
inset: -0.25rem;
}

.-inset-1\.5 {
inset: -0.375rem;
}

.inset-x-0 {
left: 0px;
right: 0px;
Expand Down Expand Up @@ -864,6 +872,10 @@ select {
margin-top: 1.5rem;
}

.ml-4 {
margin-left: 1rem;
}

.block {
display: block;
}
Expand Down Expand Up @@ -1286,6 +1298,11 @@ select {
color: rgb(255 255 255 / var(--tw-text-opacity));
}

.text-gray-400 {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}

.opacity-30 {
opacity: 0.3;
}
Expand Down Expand Up @@ -1365,6 +1382,11 @@ select {
--tw-ring-color: rgb(17 24 39 / 0.2);
}

.focus\:outline-none:focus {
outline: 2px solid transparent;
outline-offset: 2px;
}

.focus\:ring-2:focus {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
Expand All @@ -1380,6 +1402,19 @@ select {
--tw-ring-color: rgb(79 70 229 / var(--tw-ring-opacity));
}

.focus\:ring-white:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(255 255 255 / var(--tw-ring-opacity));
}

.focus\:ring-offset-2:focus {
--tw-ring-offset-width: 2px;
}

.focus\:ring-offset-gray-800:focus {
--tw-ring-offset-color: #1f2937;
}

.focus-visible\:outline:focus-visible {
outline-style: solid;
}
Expand Down Expand Up @@ -1488,6 +1523,10 @@ select {
}

@media (min-width: 768px) {
.md\:ml-6 {
margin-left: 1.5rem;
}

.md\:block {
display: block;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/ui/login/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pub fn router() -> Router<AppState> {
Router::new()
.route("/login", get(route::login_form))
.route("/login", post(route::login))
.route("/logout", get(route::logout))
}
8 changes: 8 additions & 0 deletions src/app/ui/login/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@ pub async fn login(
.unwrap(),
}
}

#[tracing::instrument(name = "Logout", skip(session))]
pub async fn logout(session: Session) -> impl IntoResponse {
session.clear().await;
session.save().await.unwrap();

Redirect::temporary("/").into_response()
}
31 changes: 18 additions & 13 deletions templates/admin_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@
</div>
</div>
</div>
<div class="hidden md:block">
<div class="ml-4 flex items-center md:ml-6">
<a href="/logout" class="bg-gray-900 text-white rounded-md px-3 py-2 text-sm font-medium"
aria-current="page">Logout</a>
</div>
</div>
</div>
</div>
</div>
</nav>
</nav>

<header class="bg-white shadow">
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
<h1 class="text-3xl font-bold tracking-tight text-gray-900">Newsletter</h1>
</div>
</header>
<main>
<div class="mx-auto max-w-7xl py-6 sm:px-6 lg:px-8">
<!-- Your content -->
<p>Hi {{ user }}! Welcome to our newsletter!</p>
</div>
</main>
<header class="bg-white shadow">
<div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">
<h1 class="text-3xl font-bold tracking-tight text-gray-900">Newsletter</h1>
</div>
</header>
<main>
<div class="mx-auto max-w-7xl py-6 sm:px-6 lg:px-8">
<!-- Your content -->
<p>Hi {{ user }}! Welcome to our newsletter!</p>
</div>
</main>
</div>

{% endblock %}
3 changes: 1 addition & 2 deletions templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ <h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gr
</h2>
</div>
<div class="mt-10 sm:mx-auto sm:w-full sm:max-w-sm">
<form class="space-y-6" hx-post="/login" hx-headers='{"X-API-KEY": "xxxxxxx"}' hx-ext="submitjson"
hx-target="#login-error" hx-swap="innerHTML">
<form class="space-y-6" hx-post="/login" hx-ext="submitjson" hx-target="#login-error" hx-swap="innerHTML">
<div>
<label for="username" class="block text-sm font-medium leading-6 text-gray-900">Username</label>
<div class="mt-2">
Expand Down

0 comments on commit 78af329

Please sign in to comment.