30 lines
793 B
Python
30 lines
793 B
Python
import re
|
|
|
|
|
|
class LoginModel:
|
|
def __init__(self, password: str, email: str):
|
|
self.password = password
|
|
self.email = email
|
|
|
|
def validate(self):
|
|
errors = []
|
|
|
|
# Check if username, password, and email are provided
|
|
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 not self.password:
|
|
errors.append("Password is required.")
|
|
if len(self.password) < 8:
|
|
errors.append("Password must be at least 8 characters.")
|
|
|
|
if errors:
|
|
return False, errors
|
|
|
|
# If all validations pass, return True
|
|
return True, []
|