gui cu modele

This commit is contained in:
andrei-mihnea-cerbu
2024-01-13 01:00:50 +02:00
parent 2a9860ebfa
commit 7eb9cdd70d
8 changed files with 112 additions and 47 deletions
@@ -0,0 +1,33 @@
import re
class SignupModel:
def __init__(self, username:str, password:str, email:str):
self.username = username
self.password = password
self.email = email
def validate(self):
errors = []
# Check if username, password, and email are provided
if not self.username:
errors.append("Username is required.")
if len(self.username) < 8:
errors.append("Username must be at least 8 characters.")
if not self.password:
errors.append("Password is required.")
if len(self.password) < 8:
errors.append("Password must be at least 8 characters.")
if not self.email:
errors.append("Email is required.")
email_pattern = re.compile(r"[^@]+@[^@]+\.[^@]+")
if not email_pattern.match(self.email):
errors.append("Invalid email format.")
if errors:
return False, errors
# If all validations pass, return True
return True, []