不在上传数据库
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
/dist
|
||||
/dist
|
||||
*.sqlite
|
||||
BIN
data.sqlite
BIN
data.sqlite
Binary file not shown.
@ -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', '{}');";
|
||||
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
19
src/main.rs
19
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
|
||||
|
||||
Reference in New Issue
Block a user