add log when setting Cookies
This commit is contained in:
parent
d119f958f6
commit
2f58427025
27
src/main.rs
27
src/main.rs
@ -1,10 +1,13 @@
|
|||||||
|
use axum::{
|
||||||
|
routing::{get, post},
|
||||||
|
Router,
|
||||||
use axum::{routing::{get, post}, Router};
|
};
|
||||||
use entities::*;
|
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::net::SocketAddr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tower_cookies::CookieManagerLayer;
|
use tower_cookies::CookieManagerLayer;
|
||||||
@ -17,6 +20,8 @@ pub mod controllers;
|
|||||||
pub mod entities;
|
pub mod entities;
|
||||||
pub mod services;
|
pub mod services;
|
||||||
use config::{HOME_URL, PORT};
|
use config::{HOME_URL, PORT};
|
||||||
|
|
||||||
|
use crate::config::*;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// 初始化日志记录器
|
// 初始化日志记录器
|
||||||
@ -32,7 +37,10 @@ async fn main() {
|
|||||||
.route("/register", get(register_page))
|
.route("/register", get(register_page))
|
||||||
.route("/register_start/:username", post(auth::start_register))
|
.route("/register_start/:username", post(auth::start_register))
|
||||||
.route("/register_finish", post(auth::finish_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))
|
.route("/webauthn_login_finish", post(finish_authentication))
|
||||||
.layer(
|
.layer(
|
||||||
TraceLayer::new_for_http()
|
TraceLayer::new_for_http()
|
||||||
@ -49,5 +57,12 @@ async fn main() {
|
|||||||
// run it with hyper on localhost:3000
|
// run it with hyper on localhost:3000
|
||||||
tokio::spawn(gc_task(state.clone()));
|
tokio::spawn(gc_task(state.clone()));
|
||||||
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
|
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();
|
axum::serve(listener, aaronhu).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,6 +91,7 @@ pub async fn login(
|
|||||||
let mut new_cookie = Cookie::new(COOKIE_NAME.to_string(), s.to_string());
|
let mut new_cookie = Cookie::new(COOKIE_NAME.to_string(), s.to_string());
|
||||||
new_cookie.set_domain(COOKIE_DOMAIN.to_string());
|
new_cookie.set_domain(COOKIE_DOMAIN.to_string());
|
||||||
cookies.add(new_cookie);
|
cookies.add(new_cookie);
|
||||||
|
tracing::info!("登录成功,设置Cookie for {}",COOKIE_DOMAIN.to_string());
|
||||||
// 从Cookie中恢复重定向信息
|
// 从Cookie中恢复重定向信息
|
||||||
let res = match original_uri{
|
let res = match original_uri{
|
||||||
Some(redirect) => Ok(Redirect::to(redirect.value())),
|
Some(redirect) => Ok(Redirect::to(redirect.value())),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user