Jelajahi Sumber

feat: 显示用户信息

SongZihuan 2 tahun lalu
induk
melakukan
37d23ed9fc
4 mengubah file dengan 36 tambahan dan 3 penghapusan
  1. 12 0
      app/auth.py
  2. 21 0
      templates/auth/user.html
  3. 2 2
      templates/comment/comment.html
  4. 1 1
      templates/comment/list.html

+ 12 - 0
app/auth.py

@@ -255,3 +255,15 @@ def logout_page():
     flash("退出登录成功")
     return redirect(url_for("base.index_page"))
 
+
+@auth.route("/user")
+def user_page():
+    user_id = request.args.get("user", -1, type=int)
+    if user_id == -1:
+        return abort(404)
+    elif current_user.is_authenticated and current_user.id == user_id:
+        return redirect(url_for("auth.auth_page"))
+    user = User.query.filter_by(id=user_id).first()
+    if not user:
+        return abort(404)
+    return render_template("auth/user.html", user=user)

+ 21 - 0
templates/auth/user.html

@@ -0,0 +1,21 @@
+{% extends "base.html" %}
+
+{% block title %} {{ user.email }} {% endblock %}
+
+{% block content %}
+    <div class="container">
+        <h5> 用户信息 </h5>
+        <ul class="list-group list-group-flush">
+            <li class="list-group-item">用户ID:{{ user.id }}</li>
+            <li class="list-group-item">用户邮箱:{{ user.email }}</li>
+            <li class="list-group-item">是否封禁:{{ "否" if user.role.has_permission(Role.USABLE) else "是" }}</li>
+        </ul>
+
+        <div class="text-end">
+            <div class="btn-group">
+                <a class="btn btn-outline-danger" href="{{ url_for("auth.logout_page") }}"> 关注 </a>
+            </div>
+        </div>
+
+    </div>
+{% endblock %}

+ 2 - 2
templates/comment/comment.html

@@ -15,7 +15,7 @@
                     <h4 class="card-title"> {{ comment.title }} </h4>
                 {% endif %}
                 <p class="card-text"> {{ comment.content }} </p>
-                <span class="badge bg-info"> {{ comment.auth.email }} </span>
+                <a class="badge bg-info text-white" href="{{ url_for("auth.user_page", user=comment.auth.id) }}"> {{ comment.auth.email }} </a>
                 <p class="text-end">
                     {% if comment.father_id %}
                         <a class="btn btn-link" href="{{ url_for("comment.comment_page", comment_id=comment.father_id) }}"> 查看父讨论 </a>
@@ -35,7 +35,7 @@
                         <h4 class="card-title"> {{ i.title }} </h4>
                     {% endif %}
                     <p class="card-text"> {{ i.content }} </p>
-                    <span class="badge bg-info"> {{ i.auth.email }} </span>
+                    <a class="badge bg-info text-white" href="{{ url_for("auth.user_page", user=i.auth.id) }}"> {{ i.auth.email }} </a>
 
                     <p class="text-end">
                         <a class="btn btn-link" href="{{ url_for("comment.comment_page", comment_id=i.id) }}"> 前往查看 </a>

+ 1 - 1
templates/comment/list.html

@@ -22,7 +22,7 @@
                             <h4 class="card-title"> {{ i.title }} </h4>
                         {% endif %}
                         <p class="card-text"> {{ i.content }} </p>
-                        <span class="badge bg-info"> {{ i.auth.email }} </span>
+                        <a class="badge bg-info text-white" href="{{ url_for("auth.user_page", user=i.auth.id) }}"> {{ i.auth.email }} </a>
 
                         <p class="text-end">
                             <a class="btn btn-link" href="{{ url_for("comment.comment_page", comment_id=i.id) }}"> 前往查看 </a>