diff --git a/.gitignore b/.gitignore index a803f50..a3c8ba4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/dist \ No newline at end of file +/dist +*.sqlite \ No newline at end of file diff --git a/data.sqlite b/data.sqlite index 8cd7286..7e7df0a 100644 Binary files a/data.sqlite and b/data.sqlite differ diff --git a/src/constant.rs b/src/constant.rs index 80254d2..2eb697f 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -2,12 +2,13 @@ use include_dir::include_dir; pub const PROJECT_DIR: include_dir::Dir = include_dir!("./template/dist"); //将前端硬编码到项目 -pub const DIST_DIR: &str = "./dist"; //前端释放目录 -// pub const DIST_DIR: &str = "./template/dist"; //前端释放目录 +// pub const DIST_DIR: &str = "./dist"; //前端释放目录 +pub const DIST_DIR: &str = "./template/dist"; //前端释放目录 pub const DATABASE: &str = "./data.sqlite"; //保存数据的目录 pub const PORT: u16 = 80; +pub const BROWER_OPEN: bool = true; pub mod sql { pub const CREATE_TABLE_TASKS: &str = " @@ -33,7 +34,7 @@ pub mod sql { id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT NOT NULL UNIQUE, password TEXT NOT NULL - );";//TODO + );"; //TODO pub const CREATE_USER_ADMIN: &str = "INSERT OR REPLACE INTO users (username, password) values ('admin', '{}');"; diff --git a/src/handlers.rs b/src/handlers.rs index 7482865..90a3cf8 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -49,7 +49,7 @@ pub async fn reg( Common::success("注册成功".to_string()) } Err(e) => match e { - sqlx::Error::Database(_) => Common::failure("该账号已注册".to_string()), + // sqlx::Error::Database(_) => Common::failure("该账号已注册".to_string()), _ => Common::failure(e.to_string()), }, } @@ -85,11 +85,11 @@ pub async fn login( pub async fn logout(mut auth_session: AuthSession, username: String) -> impl IntoResponse { match auth_session.logout().await { Ok(_) => { - info!("用户:[{}]退出登陆", username); + info!("用户:[{}]退出登陆", auth_session.user.unwrap().username); Common::success("退出登陆成功".to_string()) } Err(e) => { - error!("用户:[{}]退出登陆失败:{:?}", username, e); + error!("用户:[{}]退出登陆失败:{:?}", auth_session.user.unwrap().username, e); Common::success(format!("退出登陆失败:{:?}", e)) } } diff --git a/src/main.rs b/src/main.rs index 1e82c35..c8392d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,8 +26,8 @@ use constant::DIST_DIR; use constant::PORT; use database::Database; -use crate::constant::DATABASE; use crate::constant::PROJECT_DIR; +use crate::constant::{BROWER_OPEN, DATABASE}; use crate::routers::api_routes_init; #[tokio::main] @@ -87,20 +87,21 @@ async fn main() { .with_state(db) .layer(auth_layer) .layer(TraceLayer::new_for_http()); - // .route("/test", get())// 测试接口 //.layer(middleware::from_fn(logging_middleware)); let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{PORT}")) .await .unwrap(); info!("成功启用服务:http://0.0.0.0:{PORT}"); - match webbrowser::open(&format!("http://127.0.0.1:{PORT}")) { - Ok(_) => info!( - "成功打开浏览器并访问: {}", - &format!("http://127.0.0.1:{PORT}") - ), - Err(e) => error!("无法打开浏览器: {}", e), - }; + if BROWER_OPEN { + match webbrowser::open(&format!("http://127.0.0.1:{PORT}")) { + Ok(_) => info!( + "成功打开浏览器并访问: {}", + &format!("http://127.0.0.1:{PORT}") + ), + Err(e) => error!("无法打开浏览器: {}", e), + }; + } axum::serve(listener, app) .with_graceful_shutdown(shutdown_signal(deletion_task.abort_handle())) .await