|
|
|
@ -8,6 +8,8 @@ from werkzeug.security import generate_password_hash |
|
|
|
|
import uuid |
|
|
|
|
import os |
|
|
|
|
from config import * |
|
|
|
|
from utils.utils import password_check_sanity,is_valid_email,InsecurePasswordException |
|
|
|
|
from sqlalchemy.exc import IntegrityError |
|
|
|
|
|
|
|
|
|
profile = Blueprint('profile', __name__) |
|
|
|
|
|
|
|
|
@ -33,6 +35,16 @@ def register(): |
|
|
|
|
is_activated = True # New user will be activated initially |
|
|
|
|
profile_picture = request.files.get('profile_picture') |
|
|
|
|
|
|
|
|
|
# Validate email |
|
|
|
|
if not is_valid_email(email): |
|
|
|
|
return jsonify({"error": "Invalid email address"}), 400 |
|
|
|
|
|
|
|
|
|
# Validate password |
|
|
|
|
try: |
|
|
|
|
password_check_sanity(password) |
|
|
|
|
except InsecurePasswordException as e: |
|
|
|
|
return jsonify({"error": str(e)}), 400 |
|
|
|
|
|
|
|
|
|
# Validate required fields |
|
|
|
|
if not all([email, first_name, last_name, username, password]): |
|
|
|
|
return jsonify({"error": "Missing required fields"}), 400 |
|
|
|
@ -78,7 +90,11 @@ def register(): |
|
|
|
|
try: |
|
|
|
|
db.session.add(new_user) |
|
|
|
|
db.session.commit() |
|
|
|
|
return jsonify({"message": "User registered successfully. Please check your email to activate your account."}), 201 |
|
|
|
|
|
|
|
|
|
return jsonify({"message": "User registered successfully."}), 201 |
|
|
|
|
except IntegrityError as e: |
|
|
|
|
db.session.rollback() |
|
|
|
|
return jsonify({"error": "User with this email or username already exists."}), 400 |
|
|
|
|
except Exception as e: |
|
|
|
|
db.session.rollback() |
|
|
|
|
return jsonify({"error": "Registration failed, please try again later."}), 500 |
|
|
|
|