login si signin done
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from .login import LoginRequestModel
|
||||
from .signup import SignupRequestModel
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class LoginRequestModel:
|
||||
def __init__(self, email, password):
|
||||
self.email = email
|
||||
self.password = password
|
||||
@@ -0,0 +1,8 @@
|
||||
import json
|
||||
|
||||
|
||||
class SignupRequestModel:
|
||||
def __init__(self, username, email, password):
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.password = password
|
||||
@@ -0,0 +1,2 @@
|
||||
from .login import LoginModel
|
||||
from .signup import SignupModel
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
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, []
|
||||
|
||||
@@ -2,7 +2,7 @@ import re
|
||||
|
||||
|
||||
class SignupModel:
|
||||
def __init__(self, username:str, password:str, email:str):
|
||||
def __init__(self, username: str, password: str, email: str):
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.email = email
|
||||
|
||||
Reference in New Issue
Block a user