worked on system, added member, advisor & admin management.
This commit is contained in:
@@ -1,6 +1,38 @@
|
||||
from pickle import FALSE
|
||||
import re
|
||||
from models.database import Database
|
||||
from models.user import User
|
||||
|
||||
EMAIL_VALIDATOR = re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')
|
||||
class Validator:
|
||||
@staticmethod
|
||||
def check_email(input):
|
||||
regex = re.compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')
|
||||
return re.fullmatch(regex, input)
|
||||
|
||||
@staticmethod
|
||||
def check_username(input):
|
||||
if len(input) < 6 or len(input) > 10:
|
||||
return False
|
||||
|
||||
if not f"{input[0]}".isalpha():
|
||||
return False
|
||||
|
||||
regex = re.compile(r'^[0-9A-Za-z_.-]+$')
|
||||
if not re.fullmatch(regex, input):
|
||||
return False
|
||||
|
||||
user = User(Database.connection, None, input)
|
||||
user.load_by_username()
|
||||
|
||||
if user.id != None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def check_password(input):
|
||||
regex = re.compile(r'^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,31}$')
|
||||
return re.fullmatch(regex, input)
|
||||
|
||||
class InputMenu:
|
||||
|
||||
@@ -38,7 +70,7 @@ class InputMenu:
|
||||
|
||||
# Check regex validator id used
|
||||
if self._fields[i]['validator'] != None:
|
||||
if re.fullmatch(self._fields[i]['validator'], data):
|
||||
if self._fields[i]['validator'](data):
|
||||
# Set value of current field
|
||||
self._fields[i]['value'] = data
|
||||
break
|
||||
@@ -64,7 +96,7 @@ class InputMenu:
|
||||
try:
|
||||
num = int(data)
|
||||
if num >= self._fields[i]['min'] and num <= self._fields[i]['max']:
|
||||
self._fields[i]['value'] = data
|
||||
self._fields[i]['value'] = num
|
||||
break
|
||||
else:
|
||||
print("| Invalid input! Try again. \n|")
|
||||
|
Reference in New Issue
Block a user