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:
@@ -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