redirect to /login and redirect back, instead of showing small msg
This commit is contained in:
@@ -21,42 +21,41 @@ use crate::{
|
||||
};
|
||||
|
||||
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()?;
|
||||
|
||||
Ok(base(
|
||||
"Create User | Mnemosyne",
|
||||
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" {
|
||||
p class="flex items-center gap-2" {
|
||||
span class="text-neutral-500" {(PreEscaped(icons::USER_PLUS))}
|
||||
span class="text-2xl font-semibold font-lora" {"Create a new user"}
|
||||
}
|
||||
div class="mx-auto max-w-4xl px-2 my-4" {
|
||||
p class="flex items-center gap-2" {
|
||||
span class="text-neutral-500" {(PreEscaped(icons::USER_PLUS))}
|
||||
span class="text-2xl font-semibold font-lora" {"Create a new user"}
|
||||
}
|
||||
@if let Ok(true) = u.has_permission(&conn, Permission::ManuallyCreateUsers) {
|
||||
div class="mx-auto max-w-4xl px-2 mt-4" {
|
||||
form action="/users/create-form" method="post" class="flex flex-col" {
|
||||
label for="handle" class="font-light text-neutral-500" {"Handle"}
|
||||
div class="flex w-64 items-center border border-neutral-200/25 rounded bg-neutral-950/50" {
|
||||
span class="pl-2 text-neutral-500 select-none" {"@"}
|
||||
input id="handle" name="handle" type="text" autocomplete="off"
|
||||
class="w-fit pl-0.5 pr-1 py-1 outline-none";
|
||||
}
|
||||
label for="password" class="font-light text-neutral-500 mt-4" {"Password"} br;
|
||||
input id="password" name="password" type="password" autocomplete="off"
|
||||
class="px-2 w-64 py-1 border border-neutral-200/25 bg-neutral-950/50 rounded";
|
||||
input type="submit" value="Create"
|
||||
class="px-4 mt-4 w-64 py-1 border border-neutral-200/25 bg-neutral-200/5 rounded cursor-pointer hover:border-neutral-200/40";
|
||||
}
|
||||
@if let Ok(true) = u.has_permission(&conn, Permission::ManuallyCreateUsers) {
|
||||
div class="mx-auto max-w-4xl px-2 mt-4" {
|
||||
form action="/users/create-form" method="post" class="flex flex-col" {
|
||||
label for="handle" class="font-light text-neutral-500" {"Handle"}
|
||||
div class="flex w-64 items-center border border-neutral-200/25 rounded bg-neutral-950/50" {
|
||||
span class="pl-2 text-neutral-500 select-none" {"@"}
|
||||
input id="handle" name="handle" type="text" autocomplete="off"
|
||||
class="w-fit pl-0.5 pr-1 py-1 outline-none";
|
||||
}
|
||||
label for="password" class="font-light text-neutral-500 mt-4" {"Password"} br;
|
||||
input id="password" name="password" type="password" autocomplete="off"
|
||||
class="px-2 w-64 py-1 border border-neutral-200/25 bg-neutral-950/50 rounded";
|
||||
input type="submit" value="Create"
|
||||
class="px-4 mt-4 w-64 py-1 border border-neutral-200/25 bg-neutral-200/5 rounded cursor-pointer hover:border-neutral-200/40";
|
||||
}
|
||||
} @else {
|
||||
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."}
|
||||
p class="text-center p-2" {"You must have permission to view this page."}
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user