email is now required

This commit is contained in:
filipriec
2025-07-26 20:34:02 +02:00
parent 1fbc720620
commit c7353ac81e
2 changed files with 15 additions and 1 deletions

View File

@@ -74,7 +74,7 @@ move_left = [""]
move_right = ["right"] move_right = ["right"]
suggestion_down = ["ctrl+n", "tab"] suggestion_down = ["ctrl+n", "tab"]
suggestion_up = ["ctrl+p", "shift+tab"] suggestion_up = ["ctrl+p", "shift+tab"]
trigger_autocomplete = ["left"] trigger_autocomplete = ["tab"]
[keybindings.command] [keybindings.command]
exit_command_mode = ["ctrl+g", "esc"] exit_command_mode = ["ctrl+g", "esc"]

View File

@@ -11,6 +11,11 @@ pub async fn register(
pool: &PgPool, pool: &PgPool,
payload: RegisterRequest, payload: RegisterRequest,
) -> Result<Response<AuthResponse>, Status> { ) -> Result<Response<AuthResponse>, Status> {
// Validate required fields
if payload.email.trim().is_empty() {
return Err(Status::invalid_argument("Email is required"));
}
// Validate passwords match // Validate passwords match
if payload.password != payload.password_confirmation { if payload.password != payload.password_confirmation {
return Err(Status::invalid_argument(AuthError::PasswordMismatch.to_string())); return Err(Status::invalid_argument(AuthError::PasswordMismatch.to_string()));
@@ -41,6 +46,15 @@ pub async fn register(
if db_err.constraint() == Some("valid_roles") { if db_err.constraint() == Some("valid_roles") {
return Status::invalid_argument(format!("Invalid role specified: '{}'", role_to_insert)); return Status::invalid_argument(format!("Invalid role specified: '{}'", role_to_insert));
} }
// Check for specific constraint violations
if let Some(constraint) = db_err.constraint() {
if constraint.contains("users_username_key") {
return Status::already_exists("Username already exists".to_string());
}
if constraint.contains("users_email_key") {
return Status::already_exists("Email already exists".to_string());
}
}
} }
if e.to_string().contains("duplicate key") { if e.to_string().contains("duplicate key") {
Status::already_exists(AuthError::UserExists.to_string()) Status::already_exists(AuthError::UserExists.to_string())