}
}
/// Validate registration form data
fn validate_registration(username: &str, email: &str, password: &str, confirm_password: &str) -> Result<(), String> {
if username.trim().is_empty() {
return Err("Username is required".to_string());
}
if username.len() < 3 {
return Err("Username must be at least 3 characters long".to_string());
}
if email.trim().is_empty() {
return Err("Email is required".to_string());
}
if !email.contains('@') {
return Err("Please enter a valid email address".to_string());
}
if password.is_empty() {
return Err("Password is required".to_string());
}
if password.len() < 6 {
return Err("Password must be at least 6 characters long".to_string());
}
if password != confirm_password {
return Err("Passwords do not match".to_string());
}
Ok(())
}
/// Perform registration using the auth service
async fn perform_registration(username: String, email: String, password: String) -> Result {
use crate::auth::{AuthService, RegisterRequest};
let auth_service = AuthService::new();
let request = RegisterRequest { username, email, password };
match auth_service.register(request).await {
Ok(response) => Ok(response.token),
Err(err) => Err(err),
}
}