generated from t/malachite
add: login
This commit is contained in:
parent
ce9ce4f635
commit
8c86dd6cda
13 changed files with 407 additions and 25 deletions
|
@ -1,14 +1,19 @@
|
|||
use crate::{State, routes::default_context};
|
||||
use crate::{State, get_user_from_token, routes::default_context};
|
||||
use axum::{
|
||||
Extension,
|
||||
response::{Html, IntoResponse},
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::Error;
|
||||
|
||||
pub async fn not_found_request(Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
pub async fn not_found_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let (ref data, ref tera, ref build_code) = *data.read().await;
|
||||
let user = get_user_from_token!(jar, data.2);
|
||||
|
||||
let mut ctx = default_context(&data.0.0, &build_code);
|
||||
let mut ctx = default_context(&data.0.0, &build_code, &user);
|
||||
ctx.insert(
|
||||
"error",
|
||||
&Error::GeneralNotFound("page".to_string()).to_string(),
|
||||
|
@ -16,10 +21,28 @@ pub async fn not_found_request(Extension(data): Extension<State>) -> impl IntoRe
|
|||
return Html(tera.render("error.lisp", &ctx).unwrap());
|
||||
}
|
||||
|
||||
pub async fn index_request(Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
pub async fn index_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
let (ref data, ref tera, ref build_code) = *data.read().await;
|
||||
let user = get_user_from_token!(jar, data.2);
|
||||
|
||||
Html(
|
||||
tera.render("index.lisp", &default_context(&data.0.0, &build_code))
|
||||
.unwrap(),
|
||||
tera.render(
|
||||
"index.lisp",
|
||||
&default_context(&data.0.0, &build_code, &user),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn login_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
let (ref data, ref tera, ref build_code) = *data.read().await;
|
||||
let user = get_user_from_token!(jar, data.2);
|
||||
|
||||
Html(
|
||||
tera.render(
|
||||
"login.lisp",
|
||||
&default_context(&data.0.0, &build_code, &user),
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3,5 +3,7 @@ pub mod misc;
|
|||
use axum::routing::{Router, get};
|
||||
|
||||
pub fn routes() -> Router {
|
||||
Router::new().route("/", get(misc::index_request))
|
||||
Router::new()
|
||||
.route("/", get(misc::index_request))
|
||||
.route("/login", get(misc::login_request))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue