Initial commit
Dieser Commit ist enthalten in:
120
domain/value_objects/account_creation_params.py
Normale Datei
120
domain/value_objects/account_creation_params.py
Normale Datei
@ -0,0 +1,120 @@
|
||||
"""
|
||||
Typsichere Parameter für Account-Erstellung
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional, Dict, Any, List
|
||||
from domain.entities.browser_fingerprint import BrowserFingerprint
|
||||
|
||||
|
||||
@dataclass
|
||||
class ValidationResult:
|
||||
"""Ergebnis einer Validierung"""
|
||||
is_valid: bool
|
||||
errors: List[str]
|
||||
|
||||
def get_error_message(self) -> str:
|
||||
"""Gibt eine formatierte Fehlermeldung zurück"""
|
||||
if self.is_valid:
|
||||
return ""
|
||||
return "\n".join(self.errors)
|
||||
|
||||
|
||||
@dataclass
|
||||
class AccountCreationParams:
|
||||
"""Typsichere Parameter für Account-Erstellung"""
|
||||
full_name: str
|
||||
age: int
|
||||
registration_method: str = "email"
|
||||
show_browser: bool = False
|
||||
proxy_type: Optional[str] = None
|
||||
fingerprint: Optional[BrowserFingerprint] = None
|
||||
email_domain: str = "z5m7q9dk3ah2v1plx6ju.com"
|
||||
username: Optional[str] = None
|
||||
password: Optional[str] = None
|
||||
phone_number: Optional[str] = None
|
||||
imap_handler: Optional[Any] = None
|
||||
phone_service: Optional[Any] = None
|
||||
additional_params: Dict[str, Any] = None
|
||||
|
||||
# Platform-spezifische Konstanten
|
||||
MIN_AGE: int = 13
|
||||
MAX_AGE: int = 99
|
||||
|
||||
def __post_init__(self):
|
||||
if self.additional_params is None:
|
||||
self.additional_params = {}
|
||||
|
||||
def validate(self) -> ValidationResult:
|
||||
"""Validiert alle Parameter"""
|
||||
errors = []
|
||||
|
||||
# Name validieren
|
||||
if not self.full_name or len(self.full_name.strip()) < 2:
|
||||
errors.append("Der Name muss mindestens 2 Zeichen lang sein")
|
||||
|
||||
# Alter validieren
|
||||
if self.age < self.MIN_AGE:
|
||||
errors.append(f"Das Alter muss mindestens {self.MIN_AGE} sein")
|
||||
elif self.age > self.MAX_AGE:
|
||||
errors.append(f"Das Alter darf maximal {self.MAX_AGE} sein")
|
||||
|
||||
# Registrierungsmethode validieren
|
||||
if self.registration_method not in ["email", "phone"]:
|
||||
errors.append("Ungültige Registrierungsmethode")
|
||||
|
||||
# Telefonnummer bei Phone-Registrierung
|
||||
if self.registration_method == "phone" and not self.phone_number:
|
||||
errors.append("Telefonnummer erforderlich für Phone-Registrierung")
|
||||
|
||||
# E-Mail-Domain validieren
|
||||
if self.registration_method == "email" and not self.email_domain:
|
||||
errors.append("E-Mail-Domain erforderlich für Email-Registrierung")
|
||||
|
||||
return ValidationResult(is_valid=len(errors)==0, errors=errors)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Konvertiert zu Dictionary für Kompatibilität"""
|
||||
result = {
|
||||
"full_name": self.full_name,
|
||||
"age": self.age,
|
||||
"registration_method": self.registration_method,
|
||||
"show_browser": self.show_browser,
|
||||
"proxy_type": self.proxy_type,
|
||||
"fingerprint": self.fingerprint,
|
||||
"email_domain": self.email_domain,
|
||||
"username": self.username,
|
||||
"password": self.password,
|
||||
"phone_number": self.phone_number,
|
||||
"imap_handler": self.imap_handler,
|
||||
"phone_service": self.phone_service
|
||||
}
|
||||
|
||||
# Additional params hinzufügen
|
||||
result.update(self.additional_params)
|
||||
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: Dict[str, Any]) -> 'AccountCreationParams':
|
||||
"""Erstellt aus Dictionary"""
|
||||
# Bekannte Parameter extrahieren
|
||||
known_params = {
|
||||
"full_name": data.get("full_name", ""),
|
||||
"age": data.get("age", 18),
|
||||
"registration_method": data.get("registration_method", "email"),
|
||||
"show_browser": data.get("show_browser", False),
|
||||
"proxy_type": data.get("proxy_type"),
|
||||
"fingerprint": data.get("fingerprint"),
|
||||
"email_domain": data.get("email_domain", "z5m7q9dk3ah2v1plx6ju.com"),
|
||||
"username": data.get("username"),
|
||||
"password": data.get("password"),
|
||||
"phone_number": data.get("phone_number"),
|
||||
"imap_handler": data.get("imap_handler"),
|
||||
"phone_service": data.get("phone_service")
|
||||
}
|
||||
|
||||
# Alle anderen Parameter als additional_params
|
||||
additional = {k: v for k, v in data.items() if k not in known_params}
|
||||
known_params["additional_params"] = additional
|
||||
|
||||
return cls(**known_params)
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren