Compare commits
2 Commits
dc330b87b9
...
d520e2af98
| Author | SHA1 | Date | |
|---|---|---|---|
| d520e2af98 | |||
| 8fe84a30f6 |
@@ -37,15 +37,20 @@ CORS(app, resources={r"/*": {"origins": frontend_url}})
|
|||||||
app.config["JWT_SECRET_KEY"] = jwt_secret_key
|
app.config["JWT_SECRET_KEY"] = jwt_secret_key
|
||||||
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = jwt_access_token_expires
|
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = jwt_access_token_expires
|
||||||
|
|
||||||
|
# Security
|
||||||
bcrypt = Bcrypt(app)
|
bcrypt = Bcrypt(app)
|
||||||
jwt = JWTManager(app)
|
jwt = JWTManager(app)
|
||||||
|
|
||||||
|
# Helper Objects
|
||||||
db = PostgresConnector()
|
db = PostgresConnector()
|
||||||
auth_manager = AuthManager(db, bcrypt)
|
auth_manager = AuthManager(db, bcrypt)
|
||||||
dataset_manager = DatasetManager(db)
|
dataset_manager = DatasetManager(db)
|
||||||
stat_gen = StatGen()
|
stat_gen = StatGen()
|
||||||
connectors = get_available_connectors()
|
connectors = get_available_connectors()
|
||||||
default_topic_list = json.load(open("server/topics.json"))
|
|
||||||
|
# Default Files
|
||||||
|
with open("server/topics.json") as f:
|
||||||
|
default_topic_list = json.load(f)
|
||||||
|
|
||||||
@app.route("/register", methods=["POST"])
|
@app.route("/register", methods=["POST"])
|
||||||
def register_user():
|
def register_user():
|
||||||
|
|||||||
@@ -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