Start work on login form

This commit is contained in:
selfhoster selfhoster 2023-08-22 17:00:55 +02:00
commit 1667c3295b
4 changed files with 20 additions and 9 deletions

View file

@ -1,16 +1,19 @@
use axum::{
extract::{FromRequest, Form, Json, Query},
extract::{FromRequest, Form, Json, Query, State},
http::{self, Request, StatusCode},
response::{IntoResponse, Response},
RequestExt,
};
use axum_typed_multipart::{TryFromMultipart, TypedMultipart};
use yunohost_api::{Username, Password};
use crate::state::RoutableAppState;
#[derive(Debug, TryFromMultipart, Deserialize)]
pub struct LoginForm {
username: String,
username: Username,
#[allow(dead_code)]
password: String,
password: Password,
}
#[async_trait]
@ -52,6 +55,10 @@ where
}
#[debug_handler]
pub async fn route(form: LoginForm) -> String {
format!("Welcome {}", form.username)
pub async fn route(state: State<RoutableAppState>, form: LoginForm) -> String {
if state.check_login(&form.username, &form.password).await.unwrap() {
format!("Welcome {}", &form.username)
} else {
format!("Invalid login for {}", &form.username)
}
}