Automatic Scraping of dataset options #9
@@ -1,6 +1,10 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
from server.db.database import PostgresConnector
|
from server.db.database import PostgresConnector
|
||||||
from flask_bcrypt import Bcrypt
|
from flask_bcrypt import Bcrypt
|
||||||
|
|
||||||
|
EMAIL_REGEX = re.compile(r"[^@]+@[^@]+\.[^@]+")
|
||||||
|
|
||||||
class AuthManager:
|
class AuthManager:
|
||||||
def __init__(self, db: PostgresConnector, bcrypt: Bcrypt):
|
def __init__(self, db: PostgresConnector, bcrypt: Bcrypt):
|
||||||
self.db = db
|
self.db = db
|
||||||
@@ -18,6 +22,12 @@ class AuthManager:
|
|||||||
def register_user(self, username, email, password):
|
def register_user(self, username, email, password):
|
||||||
hashed_password = self.bcrypt.generate_password_hash(password).decode("utf-8")
|
hashed_password = self.bcrypt.generate_password_hash(password).decode("utf-8")
|
||||||
|
|
||||||
|
if len(username) < 3:
|
||||||
|
raise ValueError("Username must be longer than 3 characters")
|
||||||
|
|
||||||
|
if not EMAIL_REGEX.match(email):
|
||||||
|
raise ValueError("Please enter a valid email address")
|
||||||
|
|
||||||
if self.get_user_by_email(email):
|
if self.get_user_by_email(email):
|
||||||
raise ValueError("Email already registered")
|
raise ValueError("Email already registered")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user