Implement lightweight auth system with SQLite
Added SQLite database for session management and user preferences storage, allowing users to have consistent settings across different sessions and devices. Backend changes: - Added SQLite database with users, sessions, and preferences tables - Implemented session-based authentication alongside JWT tokens - Created preference storage/retrieval API endpoints - Database migrations for schema setup - Session validation and cleanup functionality Frontend changes: - Added "Remember server" and "Remember username" checkboxes to login - Created preferences service for syncing settings with backend - Updated auth flow to handle session tokens and preferences - Store remembered values in LocalStorage (not database) for convenience Key features: - User preferences persist across sessions and devices - CalDAV passwords never stored, only passed through - Sessions expire after 24 hours - Remember checkboxes only affect local browser storage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -46,41 +46,12 @@ pub async fn login(
|
||||
println!(" Username: {}", request.username);
|
||||
println!(" Password length: {}", request.password.len());
|
||||
|
||||
// Basic validation
|
||||
if request.username.is_empty() || request.password.is_empty() || request.server_url.is_empty() {
|
||||
return Err(ApiError::BadRequest(
|
||||
"Username, password, and server URL are required".to_string(),
|
||||
));
|
||||
}
|
||||
// Use the auth service login method which now handles database, sessions, and preferences
|
||||
let response = state.auth_service.login(request).await?;
|
||||
|
||||
println!("✅ Input validation passed");
|
||||
println!("✅ Login successful with session management");
|
||||
|
||||
// Create a token using the auth service
|
||||
println!("📝 Created CalDAV config");
|
||||
|
||||
// First verify the credentials are valid by attempting to discover calendars
|
||||
let config = CalDAVConfig::new(
|
||||
request.server_url.clone(),
|
||||
request.username.clone(),
|
||||
request.password.clone(),
|
||||
);
|
||||
let client = CalDAVClient::new(config);
|
||||
client
|
||||
.discover_calendars()
|
||||
.await
|
||||
.map_err(|e| ApiError::Unauthorized(format!("Authentication failed: {}", e)))?;
|
||||
|
||||
let token = state
|
||||
.auth_service
|
||||
.generate_token(&request.username, &request.server_url)?;
|
||||
|
||||
println!("🔗 Created CalDAV client, attempting to discover calendars...");
|
||||
|
||||
Ok(Json(AuthResponse {
|
||||
token,
|
||||
username: request.username,
|
||||
server_url: request.server_url,
|
||||
}))
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
pub async fn verify_token(
|
||||
|
||||
Reference in New Issue
Block a user