Compare commits
2 Commits
23595e8008
...
e35da127aa
| Author | SHA1 | Date | |
|---|---|---|---|
| e35da127aa | |||
|
b93cdfba63
|
@@ -71,7 +71,11 @@ pub async fn page(Query(q): Query<LoginMsg>, req: Request) -> Result<Response, A
|
|||||||
// (if javascript is disabled, login via form still works)
|
// (if javascript is disabled, login via form still works)
|
||||||
script defer {(PreEscaped(r#"
|
script defer {(PreEscaped(r#"
|
||||||
if (window.location.search) {
|
if (window.location.search) {
|
||||||
history.replaceState(null, '', window.location.pathname);
|
const url = new URL(window.location.href);
|
||||||
|
const r = url.searchParams.get('r');
|
||||||
|
url.search = '';
|
||||||
|
if (r) url.searchParams.set('r', r);
|
||||||
|
history.replaceState(null, '', url.pathname + url.search);
|
||||||
}
|
}
|
||||||
document.getElementById('login-form').addEventListener('submit', async (e) => {
|
document.getElementById('login-form').addEventListener('submit', async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -89,7 +93,12 @@ pub async fn page(Query(q): Query<LoginMsg>, req: Request) -> Result<Response, A
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
const r = new URL(window.location.href).searchParams.get('r');
|
||||||
|
if (r && r.startsWith('/')) {
|
||||||
|
window.location.href = r;
|
||||||
|
} else {
|
||||||
window.location.href = '/dashboard';
|
window.location.href = '/dashboard';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
err.textContent = text || 'Login failed';
|
err.textContent = text || 'Login failed';
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ use crate::{
|
|||||||
error::CompositeError,
|
error::CompositeError,
|
||||||
logs::LogEntry,
|
logs::LogEntry,
|
||||||
users::{User, auth::UserAuthenticate, permissions::Permission},
|
users::{User, auth::UserAuthenticate, permissions::Permission},
|
||||||
web::{RedirectViaError, components::nav::nav, icons, pages::base},
|
web::{components::nav::nav, icons, pages::base},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
||||||
let u = User::authenticate(req.headers())?
|
let u = match User::authenticate(req.headers())? {
|
||||||
.ok_or(RedirectViaError(Redirect::to("/login?re=/logs")))?;
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
let mut conn = database::conn()?;
|
let mut conn = database::conn()?;
|
||||||
let tx = conn.transaction()?;
|
let tx = conn.transaction()?;
|
||||||
let logs = LogEntry::get_all(&tx)?;
|
let logs = LogEntry::get_all(&tx)?;
|
||||||
@@ -63,7 +65,7 @@ pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} @else {
|
} @else {
|
||||||
p class="text-center p-2" {"You must have permission to view this page."}
|
p class="text-center p-2" {"You must have permission to view logs."}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,16 +20,18 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
||||||
let u = User::authenticate(req.headers())?;
|
let u = match User::authenticate(req.headers())? {
|
||||||
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
let mut conn = database::conn()?;
|
let mut conn = database::conn()?;
|
||||||
let tx = conn.transaction()?;
|
let tx = conn.transaction()?;
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"Persons | Mnemosyne",
|
"Persons | Mnemosyne",
|
||||||
html!(
|
html!(
|
||||||
(nav(u.as_ref(), req.uri().path()))
|
(nav(Some(&u), req.uri().path()))
|
||||||
|
|
||||||
@if let Some(_) = u {
|
|
||||||
div class="mx-auto max-w-4xl px-2 my-4" {
|
div class="mx-auto max-w-4xl px-2 my-4" {
|
||||||
p class="flex items-center gap-2" {
|
p class="flex items-center gap-2" {
|
||||||
span class="text-neutral-500" {(PreEscaped(icons::CONTACT))}
|
span class="text-neutral-500" {(PreEscaped(icons::CONTACT))}
|
||||||
@@ -82,9 +84,6 @@ pub async fn page(req: Request) -> Result<Response, AuthError> {
|
|||||||
} @else {
|
} @else {
|
||||||
p class="text-red-400 text-center" {"Failed to load persons."}
|
p class="text-red-400 text-center" {"Failed to load persons."}
|
||||||
}
|
}
|
||||||
} @else {
|
|
||||||
p class="text-center p-2" {"You must be logged in to view this page."}
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into_response())
|
.into_response())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::{Query, Request},
|
extract::{Query, Request},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Redirect, Response},
|
||||||
};
|
};
|
||||||
use maud::{PreEscaped, html};
|
use maud::{PreEscaped, html};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@@ -9,10 +9,7 @@ use crate::{
|
|||||||
database,
|
database,
|
||||||
error::CompositeError,
|
error::CompositeError,
|
||||||
quotes::Quote,
|
quotes::Quote,
|
||||||
users::{
|
users::{User, auth::UserAuthenticate},
|
||||||
User,
|
|
||||||
auth::{UserAuthRequired, UserAuthenticate},
|
|
||||||
},
|
|
||||||
web::{
|
web::{
|
||||||
components::{nav::nav, quote::quote},
|
components::{nav::nav, quote::quote},
|
||||||
icons,
|
icons,
|
||||||
@@ -31,7 +28,10 @@ pub async fn page(
|
|||||||
Query(query): Query<PageQuery>,
|
Query(query): Query<PageQuery>,
|
||||||
req: Request,
|
req: Request,
|
||||||
) -> Result<Response, CompositeError> {
|
) -> Result<Response, CompositeError> {
|
||||||
let u = User::authenticate(req.headers())?.required()?;
|
let u = match User::authenticate(req.headers())? {
|
||||||
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
let conn = database::conn()?;
|
let conn = database::conn()?;
|
||||||
|
|
||||||
let page = query.page.unwrap_or(1).max(1);
|
let page = query.page.unwrap_or(1).max(1);
|
||||||
|
|||||||
@@ -27,14 +27,17 @@ const LINE_ADD_RM_SCRIPT: &str = include_str!("line-add-rm.js");
|
|||||||
const PREFILL_TIME_SCRIPT: &str = include_str!("prefill-time.js");
|
const PREFILL_TIME_SCRIPT: &str = include_str!("prefill-time.js");
|
||||||
|
|
||||||
pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
||||||
let u = User::authenticate(req.headers())?;
|
let u = match User::authenticate(req.headers())? {
|
||||||
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
let conn = database::conn()?;
|
let conn = database::conn()?;
|
||||||
let names = Name::get_all(&conn)?;
|
let names = Name::get_all(&conn)?;
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"Add Quote | Mnemosyne",
|
"Add Quote | Mnemosyne",
|
||||||
html!(
|
html!(
|
||||||
(nav(u.as_ref(), req.uri().path()))
|
(nav(Some(&u), req.uri().path()))
|
||||||
|
|
||||||
div class="max-w-4xl mx-auto px-2" {
|
div class="max-w-4xl mx-auto px-2" {
|
||||||
div class="my-4 flex justify-between" {
|
div class="my-4 flex justify-between" {
|
||||||
|
|||||||
@@ -20,15 +20,17 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
||||||
let u = User::authenticate(req.headers())?;
|
let u = match User::authenticate(req.headers())? {
|
||||||
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
let conn = database::conn()?;
|
let conn = database::conn()?;
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"Tags | Mnemosyne",
|
"Tags | Mnemosyne",
|
||||||
html!(
|
html!(
|
||||||
(nav(u.as_ref(), req.uri().path()))
|
(nav(Some(&u), req.uri().path()))
|
||||||
|
|
||||||
@if let Some(_) = u {
|
|
||||||
div class="mx-auto max-w-4xl px-2 my-4" {
|
div class="mx-auto max-w-4xl px-2 my-4" {
|
||||||
p class="flex items-center gap-2" {
|
p class="flex items-center gap-2" {
|
||||||
span class="text-neutral-500" {(PreEscaped(icons::TAG))}
|
span class="text-neutral-500" {(PreEscaped(icons::TAG))}
|
||||||
@@ -81,9 +83,6 @@ pub async fn page(req: Request) -> Result<Response, AuthError> {
|
|||||||
} @else {
|
} @else {
|
||||||
p class="text-red-400 text-center" {"Failed to load tags."}
|
p class="text-red-400 text-center" {"Failed to load tags."}
|
||||||
}
|
}
|
||||||
} @else {
|
|
||||||
p class="text-center p-2" {"You must be logged in to view this page."}
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into_response())
|
.into_response())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::Request,
|
extract::Request,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Redirect, Response},
|
||||||
};
|
};
|
||||||
use maud::{PreEscaped, html};
|
use maud::{PreEscaped, html};
|
||||||
|
|
||||||
@@ -22,19 +22,18 @@ pub mod create;
|
|||||||
pub mod profile;
|
pub mod profile;
|
||||||
|
|
||||||
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
||||||
let u = User::authenticate(req.headers())?;
|
let u = match User::authenticate(req.headers())? {
|
||||||
let conn = database::conn()?;
|
Some(u) => u,
|
||||||
let us = match u.is_some() {
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
true => User::get_all(&conn),
|
|
||||||
false => Ok(vec![]),
|
|
||||||
};
|
};
|
||||||
|
let conn = database::conn()?;
|
||||||
|
let us = User::get_all(&conn);
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"Users | Mnemosyne",
|
"Users | Mnemosyne",
|
||||||
html!(
|
html!(
|
||||||
(nav(u.as_ref(), req.uri().path()))
|
(nav(Some(&u), req.uri().path()))
|
||||||
|
|
||||||
@if let Some(u) = u {
|
|
||||||
div class="mx-auto max-w-4xl px-2 my-4" {
|
div class="mx-auto max-w-4xl px-2 my-4" {
|
||||||
p class="flex items-center gap-2" {
|
p class="flex items-center gap-2" {
|
||||||
span class="text-neutral-500" {(PreEscaped(icons::USERS))}
|
span class="text-neutral-500" {(PreEscaped(icons::USERS))}
|
||||||
@@ -63,9 +62,6 @@ pub async fn page(req: Request) -> Result<Response, AuthError> {
|
|||||||
p class="text-center py-4 text-light text-red-500" {"Failed to load users."}
|
p class="text-center py-4 text-light text-red-500" {"Failed to load users."}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} @else {
|
|
||||||
p class="text-center p-2" {"You must be logged in to view this page."}
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into_response())
|
.into_response())
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
||||||
let u = User::authenticate(req.headers())?;
|
let u = match User::authenticate(req.headers())? {
|
||||||
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
let conn = database::conn()?;
|
let conn = database::conn()?;
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"Create User | Mnemosyne",
|
"Create User | Mnemosyne",
|
||||||
html!(
|
html!(
|
||||||
(nav(u.as_ref(), req.uri().path()))
|
(nav(Some(&u), req.uri().path()))
|
||||||
|
|
||||||
@if let Some(u) = u {
|
|
||||||
div class="mx-auto max-w-4xl px-2 my-4" {
|
div class="mx-auto max-w-4xl px-2 my-4" {
|
||||||
p class="flex items-center gap-2" {
|
p class="flex items-center gap-2" {
|
||||||
span class="text-neutral-500" {(PreEscaped(icons::USER_PLUS))}
|
span class="text-neutral-500" {(PreEscaped(icons::USER_PLUS))}
|
||||||
@@ -55,9 +57,6 @@ pub async fn page(req: Request) -> Result<Response, AuthError> {
|
|||||||
} @else {
|
} @else {
|
||||||
p class="text-center p-2" {"You must have permission to view this page."}
|
p class="text-center p-2" {"You must have permission to view this page."}
|
||||||
}
|
}
|
||||||
} @else {
|
|
||||||
p class="text-center p-2" {"You must be logged in to view this page."}
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into_response())
|
.into_response())
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use crate::{
|
|||||||
pub async fn page(Path(id): Path<Uuid>, req: Request) -> Result<Response, CompositeError> {
|
pub async fn page(Path(id): Path<Uuid>, req: Request) -> Result<Response, CompositeError> {
|
||||||
let u = match User::authenticate(req.headers())? {
|
let u = match User::authenticate(req.headers())? {
|
||||||
Some(u) => u,
|
Some(u) => u,
|
||||||
None => return Ok(Redirect::to("/users").into_response()),
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
};
|
};
|
||||||
let mut conn = database::conn()?;
|
let mut conn = database::conn()?;
|
||||||
let tx = conn.transaction()?;
|
let tx = conn.transaction()?;
|
||||||
|
|||||||
@@ -20,14 +20,16 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
pub async fn page(req: Request) -> Result<Response, AuthError> {
|
||||||
let u = User::authenticate(req.headers())?;
|
let u = match User::authenticate(req.headers())? {
|
||||||
|
Some(u) => u,
|
||||||
|
None => return Ok(Redirect::to(&format!("/login?r={}", req.uri().path())).into_response()),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(base(
|
Ok(base(
|
||||||
"User Settings | Mnemosyne",
|
"User Settings | Mnemosyne",
|
||||||
html!(
|
html!(
|
||||||
(nav(u.as_ref(), req.uri().path()))
|
(nav(Some(&u), req.uri().path()))
|
||||||
|
|
||||||
@if let Some(u) = u {
|
|
||||||
div class="max-w-4xl mx-auto px-2" {
|
div class="max-w-4xl mx-auto px-2" {
|
||||||
div class="mx-auto max-w-4xl my-4" {
|
div class="mx-auto max-w-4xl my-4" {
|
||||||
p class="flex items-center gap-2" {
|
p class="flex items-center gap-2" {
|
||||||
@@ -65,9 +67,6 @@ pub async fn page(req: Request) -> Result<Response, AuthError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} @else {
|
|
||||||
p class="text-center p-2" {"You must be logged in to view this page."}
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into_response())
|
.into_response())
|
||||||
|
|||||||
Reference in New Issue
Block a user