diff --git a/src/flask_prompt_master/routes/__pycache__/auth.cpython-312.pyc b/src/flask_prompt_master/routes/__pycache__/auth.cpython-312.pyc index 00a2bec..1452559 100644 Binary files a/src/flask_prompt_master/routes/__pycache__/auth.cpython-312.pyc and b/src/flask_prompt_master/routes/__pycache__/auth.cpython-312.pyc differ diff --git a/src/flask_prompt_master/routes/auth.py b/src/flask_prompt_master/routes/auth.py index 4d1b855..2401aaa 100644 --- a/src/flask_prompt_master/routes/auth.py +++ b/src/flask_prompt_master/routes/auth.py @@ -92,6 +92,11 @@ def get_profile(): """获取个人资料API""" user_id = session['user_id'] result = AuthService.get_user_by_id(user_id) + if result['success']: + return jsonify({ + 'success': True, + 'data': result['user'] + }) return jsonify(result) @auth_bp.route('/api/profile', methods=['PUT']) @@ -147,3 +152,57 @@ def check_login(): 'success': True, 'logged_in': False }) + +@auth_bp.route('/api/profile/stats', methods=['GET']) +@login_required +def get_profile_stats(): + """获取用户使用统计API""" + user_id = session['user_id'] + + try: + from src.flask_prompt_master.models.models import Prompt + from src.flask_prompt_master.models.favorites import Favorite + from sqlalchemy import func + + # 统计生成的提示词数量 + total_prompts = Prompt.query.filter_by(user_id=user_id).count() + + # 统计收藏数量 + total_favorites = Favorite.query.filter_by(user_id=str(user_id)).count() + + # 计算活跃天数(从注册时间到现在) + from src.flask_prompt_master.models.models import User + user = User.query.get(user_id) + days_active = 0 + if user and user.created_time: + from datetime import datetime + days_active = (datetime.now() - user.created_time).days + 1 + + # 获取最近活动 + recent_prompts = Prompt.query.filter_by(user_id=user_id)\ + .order_by(Prompt.created_at.desc())\ + .limit(5).all() + + recent_activities = [] + for prompt in recent_prompts: + recent_activities.append({ + 'type': '生成提示词', + 'content': prompt.input_text[:30] + '...' if len(prompt.input_text) > 30 else prompt.input_text, + 'time': prompt.created_at.strftime('%Y-%m-%d %H:%M:%S') if prompt.created_at else '' + }) + + return jsonify({ + 'success': True, + 'data': { + 'total_prompts': total_prompts, + 'total_favorites': total_favorites, + 'days_active': days_active, + 'recent_activities': recent_activities + } + }) + + except Exception as e: + return jsonify({ + 'success': False, + 'message': f'获取统计信息失败: {str(e)}' + }) diff --git a/src/flask_prompt_master/templates/auth/profile.html b/src/flask_prompt_master/templates/auth/profile.html new file mode 100644 index 0000000..162e3e6 --- /dev/null +++ b/src/flask_prompt_master/templates/auth/profile.html @@ -0,0 +1,408 @@ +{% extends "base.html" %} + +{% block title %}个人资料 - 提示词大师{% endblock %} + +{% block content %} +
+
+ +
+
+
+
个人中心
+
+
+ +
+
+
+ + +
+
+ +
+
+
+

基本信息

+
+
+
+
+
+ + +
+
+ + + 用户名不可修改 +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ +
+ 头像 + + +
+
+
+ +
+
+ + +
+
+ + +
+
+ +
+ +
+
+
+
+
+ + +
+
+
+

修改密码

+
+
+
+
+ + +
+ +
+ + +
密码长度至少6位,建议包含字母、数字和特殊字符
+
+ +
+ + +
+ +
+ +
+
+
+
+
+ + +
+
+
+

使用统计

+
+
+
+
+
+
+

0

+

生成提示词

+
+
+
+
+
+
+

0

+

收藏数量

+
+
+
+
+
+
+

0

+

活跃天数

+
+
+
+
+ +
+
+
最近活动
+
+

加载中...

+
+
+
+
+
+
+
+
+
+
+ + + + + + +{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/src/flask_prompt_master/templates/base.html b/src/flask_prompt_master/templates/base.html index c7ef6e3..5615d2b 100644 --- a/src/flask_prompt_master/templates/base.html +++ b/src/flask_prompt_master/templates/base.html @@ -258,6 +258,10 @@ 我的收藏 + + + 个人资料 +