first round of review

This commit is contained in:
counterweight 2025-12-19 10:30:23 +01:00
parent 5908660e56
commit 7140cf6f27
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
9 changed files with 61 additions and 63 deletions

View file

@ -1,5 +1,4 @@
"""Validation utilities for user profile fields."""
import re
from email_validator import validate_email, EmailNotValidError
from bech32 import bech32_decode
@ -25,7 +24,7 @@ def validate_telegram(value: str | None) -> str | None:
"""
Validate Telegram handle.
Must start with @ if provided.
Must start with @ if provided, with 1-32 characters after @.
Returns None if valid, error message if invalid.
Empty/None values are valid (field is optional).
"""
@ -35,21 +34,13 @@ def validate_telegram(value: str | None) -> str | None:
if not value.startswith("@"):
return "Telegram handle must start with @"
if len(value) < 2:
return "Telegram handle must have at least one character after @"
# Telegram usernames: 5-32 characters, alphanumeric and underscores
# But we store with @, so check 6-33 total
handle = value[1:] # Remove @
if len(handle) < 5:
return "Telegram handle must be at least 5 characters (after @)"
if len(handle) < 1:
return "Telegram handle must have at least one character after @"
if len(handle) > 32:
return "Telegram handle must be at most 32 characters (after @)"
if not re.match(r'^[a-zA-Z][a-zA-Z0-9_]*$', handle):
return "Telegram handle must start with a letter and contain only letters, numbers, and underscores"
return None