From 489f02a5d6957a066b6e9d46942c634f014b6c9c Mon Sep 17 00:00:00 2001 From: man_tks Date: Mon, 27 Apr 2026 13:43:51 +0700 Subject: [PATCH 1/5] profile update --- backend/src/routes/api_auth_routes.py | 60 +++++++++--- frontend/src/templates/booking_detail.html | 47 +++++++++ frontend/src/templates/event_detail.html | 47 +++++++++ frontend/src/templates/history.html | 46 +++++++++ frontend/src/templates/index.html | 47 ++++++++- frontend/src/templates/profile.html | 105 ++++++++++++++++++--- frontend/src/templates/search_events.html | 47 +++++++++ frontend/src/templates/tickets.html | 47 +++++++++ 8 files changed, 421 insertions(+), 25 deletions(-) diff --git a/backend/src/routes/api_auth_routes.py b/backend/src/routes/api_auth_routes.py index 212f19d..d8cdd2e 100644 --- a/backend/src/routes/api_auth_routes.py +++ b/backend/src/routes/api_auth_routes.py @@ -1,8 +1,8 @@ -# File: backend/src/routes/api_auth_routes.py from flask import Blueprint, request, jsonify from services.auth_service import register_new_user, verify_login from flask_jwt_extended import jwt_required, get_jwt_identity -import datetime +from models import db, User, Customer, Organizer +from utils import upload_avatar_to_cloudinary api_auth_bp = Blueprint('api_auth', __name__, url_prefix='/api/v1/auth') @@ -50,15 +50,13 @@ def api_login(): @api_auth_bp.route('/me', methods=['GET']) @jwt_required() def get_my_profile(): - from models import User - identity = get_jwt_identity() if isinstance(identity, dict): current_user_id = identity.get('id') else: current_user_id = identity - user = User.query.get(current_user_id) + user = db.session.get(User, current_user_id) if not user: return jsonify({"status": "error", "message": "User not found"}), 404 @@ -71,16 +69,56 @@ def get_my_profile(): } if user.type == 'customer': - from models import Customer - customer = Customer.query.get(user.id) + customer = db.session.get(Customer, user.id) if customer and customer.tier: user_data["tier"] = customer.tier.name - elif user.type == 'organizer': - from models import Organizer - org = Organizer.query.get(user.id) + org = db.session.get(Organizer, user.id) if org: user_data["company_name"] = org.company_name user_data["bank_account"] = org.bank_account - return jsonify({"status": "success", "user": user_data}), 200 \ No newline at end of file + return jsonify({"status": "success", "user": user_data}), 200 + + +@api_auth_bp.route('/me', methods=['PUT']) +@jwt_required() +def update_my_profile(): + identity = get_jwt_identity() + if isinstance(identity, dict): + current_user_id = identity.get('id') + else: + current_user_id = identity + + user = db.session.get(User, current_user_id) + if not user: + return jsonify({"status": "error", "message": "User not found"}), 404 + + if user.type != 'customer': + return jsonify({"status": "error", "message": "Chỉ khách hàng mới được cập nhật hồ sơ"}), 403 + + avatar_file = request.files.get('avatar') + if avatar_file: + avatar_url = upload_avatar_to_cloudinary(avatar_file) + user.avatar = avatar_url + + name = request.form.get('name') + if name: + user.name = name + + db.session.commit() + + user_data = { + "id": user.id, "name": user.name, "email": user.email, + "phone_number": user.phone_number, "username": user.username, + "avatar": user.avatar, + "dob": user.dob.strftime('%Y-%m-%d') if user.dob else None, + "type": user.type + } + + if user.type == 'customer': + customer = db.session.get(Customer, user.id) + if customer and customer.tier: + user_data["tier"] = customer.tier.name + + return jsonify({"status": "success", "message": "Cập nhật thành công!", "user": user_data}), 200 \ No newline at end of file diff --git a/frontend/src/templates/booking_detail.html b/frontend/src/templates/booking_detail.html index c5a52c4..c2698ef 100644 --- a/frontend/src/templates/booking_detail.html +++ b/frontend/src/templates/booking_detail.html @@ -10,6 +10,8 @@ + + @@ -102,6 +104,51 @@
Vé / Ghế + diff --git a/frontend/src/templates/event_detail.html b/frontend/src/templates/event_detail.html index 3d7147b..fe62f4f 100644 --- a/frontend/src/templates/event_detail.html +++ b/frontend/src/templates/event_detail.html @@ -10,6 +10,8 @@ + + @@ -154,6 +156,51 @@
Vé đã ch + diff --git a/frontend/src/templates/history.html b/frontend/src/templates/history.html index 1c2f031..84b8c65 100644 --- a/frontend/src/templates/history.html +++ b/frontend/src/templates/history.html @@ -10,6 +10,7 @@ +