add log when setting Cookies

This commit is contained in:
yly 2024-03-14 22:40:57 +08:00
parent d119f958f6
commit 2f58427025
2 changed files with 22 additions and 6 deletions

View File

@ -1,10 +1,13 @@
use axum::{routing::{get, post}, Router};
use axum::{
routing::{get, post},
Router,
};
use entities::*;
use services::{auth::{self, finish_authentication, start_authentication}, gc_task, login, login_page, register_page};
use services::{
auth::{self, finish_authentication, start_authentication},
gc_task, login, login_page, register_page,
};
use std::net::SocketAddr;
use std::sync::Arc;
use tower_cookies::CookieManagerLayer;
@ -17,6 +20,8 @@ pub mod controllers;
pub mod entities;
pub mod services;
use config::{HOME_URL, PORT};
use crate::config::*;
#[tokio::main]
async fn main() {
// 初始化日志记录器
@ -32,7 +37,10 @@ async fn main() {
.route("/register", get(register_page))
.route("/register_start/:username", post(auth::start_register))
.route("/register_finish", post(auth::finish_register))
.route("/webauthn_login_start/:username", post(start_authentication))
.route(
"/webauthn_login_start/:username",
post(start_authentication),
)
.route("/webauthn_login_finish", post(finish_authentication))
.layer(
TraceLayer::new_for_http()
@ -49,5 +57,12 @@ async fn main() {
// run it with hyper on localhost:3000
tokio::spawn(gc_task(state.clone()));
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
tracing::info!(
"配置如下 COOKIE_DOMAIN={}\nRP_ID={}\nRP_ORIGIN={}\nCOOKIE_NAME={}\n",
COOKIE_DOMAIN.to_string(),
RP_ID.to_string(),
RP_ORIGIN.to_string(),
COOKIE_NAME.to_string()
);
axum::serve(listener, aaronhu).await.unwrap();
}

View File

@ -91,6 +91,7 @@ pub async fn login(
let mut new_cookie = Cookie::new(COOKIE_NAME.to_string(), s.to_string());
new_cookie.set_domain(COOKIE_DOMAIN.to_string());
cookies.add(new_cookie);
tracing::info!("登录成功设置Cookie for {}",COOKIE_DOMAIN.to_string());
// 从Cookie中恢复重定向信息
let res = match original_uri{
Some(redirect) => Ok(Redirect::to(redirect.value())),