|
|
@ -1,5 +1,5 @@ |
|
|
|
from email.policy import default |
|
|
|
from email.policy import default |
|
|
|
from flask import Blueprint, request, jsonify, current_app, g |
|
|
|
from flask import Blueprint, request, jsonify, current_app, g,url_for |
|
|
|
from werkzeug.utils import secure_filename |
|
|
|
from werkzeug.utils import secure_filename |
|
|
|
from datetime import datetime |
|
|
|
from datetime import datetime |
|
|
|
from utils.auth import auth_required, requires_role |
|
|
|
from utils.auth import auth_required, requires_role |
|
|
@ -12,7 +12,7 @@ import os |
|
|
|
from config import * |
|
|
|
from config import * |
|
|
|
from utils.utils import password_check_sanity,is_valid_email,InsecurePasswordException |
|
|
|
from utils.utils import password_check_sanity,is_valid_email,InsecurePasswordException |
|
|
|
from sqlalchemy.exc import IntegrityError |
|
|
|
from sqlalchemy.exc import IntegrityError |
|
|
|
|
|
|
|
# from flask import url_for |
|
|
|
profile = Blueprint('profile', __name__) |
|
|
|
profile = Blueprint('profile', __name__) |
|
|
|
|
|
|
|
|
|
|
|
# Function to check allowed file extensions |
|
|
|
# Function to check allowed file extensions |
|
|
@ -103,8 +103,37 @@ def register(): |
|
|
|
return jsonify({"error": "Registration failed, please try again later."}), 500 |
|
|
|
return jsonify({"error": "Registration failed, please try again later."}), 500 |
|
|
|
|
|
|
|
|
|
|
|
#make a get request to get json on hello word |
|
|
|
#make a get request to get json on hello word |
|
|
|
@profile.route('/hello') |
|
|
|
@profile.route('/me', methods=['GET']) |
|
|
|
@auth_required() |
|
|
|
@auth_required() |
|
|
|
@requires_role([UserRole.USER]) |
|
|
|
def get_profile(): |
|
|
|
def hello(): |
|
|
|
""" |
|
|
|
return jsonify({"message": f"Hello {g.current_user.firstName}"}), 200 |
|
|
|
Fetch the profile details of the currently logged-in user. |
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
# Get the current user from the `@auth_required` decorator |
|
|
|
|
|
|
|
current_user: User = g.current_user |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profile_url = url_for('send_file', filename=current_user.pfpFilename, _external=True) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
profile_url = "" |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
# Construct the user profile data |
|
|
|
|
|
|
|
profile_data = { |
|
|
|
|
|
|
|
"id": str(current_user.id), |
|
|
|
|
|
|
|
"email": current_user.email, |
|
|
|
|
|
|
|
"first_name": current_user.firstName, |
|
|
|
|
|
|
|
"last_name": current_user.lastName, |
|
|
|
|
|
|
|
"username": current_user.username, |
|
|
|
|
|
|
|
"dob": current_user.dob.isoformat(), |
|
|
|
|
|
|
|
"joined_date": current_user.joinedDate.isoformat(), |
|
|
|
|
|
|
|
"last_online": current_user.lastOnline.isoformat(), |
|
|
|
|
|
|
|
"bio": current_user.bio, |
|
|
|
|
|
|
|
"role": current_user.role, |
|
|
|
|
|
|
|
"pfp_filename": current_user.pfpFilename, |
|
|
|
|
|
|
|
"profile_url":profile_url |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return jsonify({"profile": profile_data}), 200 |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
return jsonify({"error": f"Failed to fetch profile. Error: {str(e)}"}), 500 |
|
|
|
|
|
|
|
|
|
|
|