Merge branch 'staging' into 'main'

Staging

See merge request PhilippHofer/rot!45
This commit is contained in:
PhilippHofer 2023-10-24 11:51:03 +00:00
commit 415bc45f2e

View File

@ -1,11 +1,12 @@
use rocket::{
catch, catchers,
fairing::AdHoc,
form::Form,
fs::FileServer,
get,
get, post,
request::FlashMessage,
response::{Flash, Redirect},
routes, Build, Rocket, State,
routes, Build, FromForm, Rocket, State,
};
use rocket_dyn_templates::{tera::Context, Template};
use serde::Deserialize;
@ -27,6 +28,20 @@ mod log;
mod misc;
mod stat;
#[derive(FromForm, Debug)]
struct LoginForm<'r> {
name: &'r str,
password: &'r str,
}
#[post("/", data = "<login>")]
async fn wikiauth(db: &State<SqlitePool>, login: Form<LoginForm<'_>>) -> String {
match User::login(db, login.name, login.password).await {
Ok(_) => "SUCC".into(),
Err(_) => "FAIL".into(),
}
}
#[get("/")]
async fn index(db: &State<SqlitePool>, user: User, flash: Option<FlashMessage<'_>>) -> Template {
let mut context = Context::new();
@ -195,6 +210,7 @@ pub fn config(rocket: Rocket<Build>) -> Rocket<Build> {
rocket
.mount("/", routes![index, join, remove, remove_guest])
.mount("/auth", auth::routes())
.mount("/wikiauth", routes![wikiauth])
.mount("/log", log::routes())
.mount("/stat", stat::routes())
.mount("/boatdamage", boatdamage::routes())