34 lines
1023 B
Python
34 lines
1023 B
Python
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, []
|