Add login/logout to Momentry Studio sidebar with default demo/demo123
- Added login/logout buttons to left sidebar bottom - Shows current user name when logged in - Login modal with username/password fields - Default credentials: demo/demo123 - auth_login Tauri command using SqliteProvider
This commit is contained in:
Generated
+17
@@ -3570,6 +3570,7 @@ dependencies = [
|
||||
"tokio-postgres",
|
||||
"tokio-util",
|
||||
"toml 0.8.23",
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"ureq",
|
||||
@@ -7120,6 +7121,22 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-http"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5"
|
||||
dependencies = [
|
||||
"bitflags 2.13.0",
|
||||
"bytes",
|
||||
"http 1.4.2",
|
||||
"http-body 1.0.1",
|
||||
"http-body-util",
|
||||
"pin-project-lite",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.3"
|
||||
|
||||
@@ -10,6 +10,13 @@ pub struct UserInfo {
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct LoginResult {
|
||||
pub success: bool,
|
||||
pub username: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref DATA_PROVIDER: LazyLock<Arc<Mutex<Box<dyn DataProvider>>>> =
|
||||
LazyLock::new(|| {
|
||||
@@ -20,6 +27,27 @@ lazy_static::lazy_static! {
|
||||
});
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn auth_login(username: String, password: String) -> Result<LoginResult, String> {
|
||||
let provider = DATA_PROVIDER.lock().unwrap();
|
||||
|
||||
let valid = provider.check_password(&username, &password).map_err(|e| e.to_string())?;
|
||||
|
||||
if valid {
|
||||
Ok(LoginResult {
|
||||
success: true,
|
||||
username: username.clone(),
|
||||
message: "Login successful".to_string(),
|
||||
})
|
||||
} else {
|
||||
Ok(LoginResult {
|
||||
success: false,
|
||||
username: String::new(),
|
||||
message: "Invalid username or password".to_string(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_auth_users() -> Result<Vec<UserInfo>, String> {
|
||||
let provider = DATA_PROVIDER.lock().unwrap();
|
||||
|
||||
@@ -42,6 +42,7 @@ fn main() {
|
||||
get_backup_config,
|
||||
set_backup_config,
|
||||
run_backup,
|
||||
auth_login,
|
||||
list_auth_users,
|
||||
create_auth_user,
|
||||
update_auth_user,
|
||||
|
||||
Reference in New Issue
Block a user