diff --git a/src/tera/mod.rs b/src/tera/mod.rs index 145b404..799ae24 100644 --- a/src/tera/mod.rs +++ b/src/tera/mod.rs @@ -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 = "")] +async fn wikiauth(db: &State, login: Form>) -> String { + match User::login(db, login.name, login.password).await { + Ok(_) => "SUCC".into(), + Err(_) => "FAIL".into(), + } +} + #[get("/")] async fn index(db: &State, user: User, flash: Option>) -> Template { let mut context = Context::new(); @@ -195,6 +210,7 @@ pub fn config(rocket: Rocket) -> Rocket { 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())