浏览代码

feat: 新增web的登录退出功能

SongZihuan 3 年之前
父节点
当前提交
b2b6ed5de9

+ 36 - 4
app/__init__.py

@@ -1,17 +1,49 @@
 from flask import Flask
 from flask import Flask
+from waitress import serve
 
 
+from conf import Config
 from tool.type_ import *
 from tool.type_ import *
 from sql.db import DB
 from sql.db import DB
 
 
 from . import views as views
 from . import views as views
 
 
-app: Optional[Flask] = None
+app: Optional["App"] = None
 
 
 
 
-def creat_web(db: DB) -> Flask:
+class App:
+    app: Optional["App"] = None
+
+    def __new__(cls, *args, **kwargs):
+        if App.app is not None:
+            return App.app
+        return object.__new__(cls)
+
+    def __init__(self):
+        self._app = Flask(__name__)
+
+    def conf(self, db: DB):
+        self._app.config["SECRET_KEY"] = Config.wtf_secret  # FlaskForm 需要使用
+        views.register(self._app, db)
+
+    def run_waitress(self, **kw):
+        serve(self._app, **kw)
+
+    def run_flask(self,
+                  host: Optional[str] = None,
+                  port: Optional[int] = None,
+                  debug: Optional[bool] = True if Config.run_type == "debug" else None,
+                  load_dotenv: bool = True,
+                  **options: any):
+        self._app.run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options)
+
+    def get_app(self):
+        return self._app
+
+
+def creat_web(db: DB) -> App:
     global app
     global app
     if app is not None:
     if app is not None:
         return app
         return app
-    app = Flask(__name__)
-    views.register(app, db)
+    app = App()
+    app.conf(db)
     return app
     return app

+ 2 - 0
app/auth/__init__.py

@@ -0,0 +1,2 @@
+from . import views as auth_views
+from . import web as auth_web

+ 63 - 0
app/auth/views.py

@@ -0,0 +1,63 @@
+from flask import render_template, Blueprint, Flask, request, url_for, redirect, flash
+from wtforms import StringField, PasswordField, SubmitField
+from wtforms.validators import DataRequired
+from flask_wtf import FlaskForm
+from flask_login import LoginManager, login_required, login_user, logout_user
+
+from tool.type_ import *
+from sql.db import DB
+from .web import AuthWebsite
+
+auth = Blueprint("auth", __name__)
+auth_website: Optional[AuthWebsite] = None
+app: Optional[Flask] = None
+
+login_manager = LoginManager()
+login_manager.login_view = 'auth.login'
+
+
+class LoginForm(FlaskForm):
+    name = StringField("你的用户名是?", validators=[DataRequired()])
+    passwd = PasswordField("用户密码是?", validators=[DataRequired()])
+    submit = SubmitField("登录")
+
+
+@auth.route('/login', methods=['GET', 'POST'])
+def login():
+    form = LoginForm()
+    if form.validate_on_submit():
+        name = form.name.data
+        passwd = form.passwd.data
+        check = auth_website.load_user_by_name(name, passwd)
+
+        if check is not None:
+            login_user(user=check, remember=True)
+            next_page: str = request.args.get('next')
+            if next_page is None or not next_page.startswith('/'):
+                next_page = url_for("hello.index")
+            return redirect(next_page)
+
+        flash("用户错误")
+    return render_template("auth/login.html", form=form)
+
+
+@login_manager.user_loader
+def load_user(user: uid_t):
+    return auth_website.load_user_by_id(user)
+
+
+@auth.route("/logout")
+@login_required
+def logout():
+    logout_user()
+    flash("用户退出成功")
+    return redirect(url_for("hello.index"))
+
+
+def creat_auth_website(app_: Flask, db: DB):
+    global auth_website, app
+    if auth_website is None:
+        app = app_
+        auth_website = AuthWebsite(app, db)
+        login_manager.init_app(app)
+        app.register_blueprint(auth, url_prefix="/auth")

+ 51 - 0
app/auth/web.py

@@ -0,0 +1,51 @@
+from flask import Flask
+
+from tool.login import create_uid
+from sql.db import DB
+from sql.user import find_user_by_name, find_user_by_id
+from tool.type_ import *
+from . import views
+
+
+class WebUser:
+    def __init__(self, name: uname_t, passwd: passwd_t = None, uid: uid_t = None):
+        self._name = name
+        if uid is None:
+            self._uid = create_uid(name, passwd)
+        else:
+            self._uid = uid
+        self.is_anonymous = False
+
+    @property
+    def name(self):
+        return self._name
+
+    @property
+    def is_active(self):
+        return views.auth_website.load_user_by_id(self._uid) is not None
+
+    @property
+    def is_authenticated(self):
+        return views.auth_website.load_user_by_id(self._uid) is not None
+
+    def get_id(self):
+        return self._uid
+
+
+class AuthWebsite:
+    def __init__(self, app: Flask, db: DB):
+        self._app = app
+        self._db = db
+
+    def load_user_by_name(self, name: uname_t, passwd: passwd_t) -> Optional[WebUser]:
+        user = find_user_by_name(name, passwd, self._db)
+        if user is None:
+            return None
+        return WebUser(name, uid=user.get_uid())
+
+    def load_user_by_id(self, uid: uid_t) -> Optional[WebUser]:
+        user = find_user_by_id(uid, self._db)
+        if user is None:
+            return None
+        name = user.get_name()
+        return WebUser(name, uid=uid)

+ 0 - 28
app/hello_views.py

@@ -1,28 +0,0 @@
-from conf import Config
-from flask import render_template, Blueprint, Flask
-from tool.type_ import Optional
-
-hello_web = Blueprint("hello_web", __name__)
-hello_app: Optional[Flask] = None
-
-
-@hello_web.route('/')
-def index():
-    return render_template("hello_web/index.html", loc=Config.base_location)
-
-
-@hello_web.route('/start')
-def start():
-    return render_template("hello_web/start.html", loc=Config.base_location)
-
-
-@hello_web.app_errorhandler(404)
-def error_404(e):
-    return render_template("hello_web/error.html", error_code="404", error_info=e), 404
-
-
-def creat_hello_website(app: Flask):
-    global hello_app
-    if hello_app is not None:
-        return hello_app
-    app.register_blueprint(hello_web)

+ 1 - 0
app/index/__init__.py

@@ -0,0 +1 @@
+from . import views as hello_views

+ 35 - 0
app/index/views.py

@@ -0,0 +1,35 @@
+from conf import Config
+from flask import render_template, Blueprint, Flask
+from tool.type_ import Optional
+
+hello = Blueprint("hello", __name__)
+app: Optional[Flask] = None
+
+
+@hello.route('/')
+def start():
+    return render_template("hello/start.html")
+
+
+@hello.route('/start')
+def index():
+    return render_template("hello/index.html")
+
+
+@hello.app_errorhandler(404)
+def error_404(e):
+    return render_template("hello/error.html", error_code="404", error_info=e), 404
+
+
+@hello.app_context_processor
+def inject_base():
+    return {"loc": Config.base_location,
+            "copy_right": "SuperHuan",
+            "github_link": r"https://github.com/SuperH-0630/HGSSystem"}
+
+
+def creat_hello_website(app_: Flask):
+    global app
+    if app is None:
+        app = app_
+        app.register_blueprint(hello)

+ 2 - 0
app/rank/__init__.py

@@ -0,0 +1,2 @@
+from . import views as rank_views
+from . import web as rank_web

+ 30 - 0
app/rank/views.py

@@ -0,0 +1,30 @@
+from flask import render_template, Blueprint, Flask
+from .web import RankWebsite
+from sql.db import DB
+from tool.type_ import Optional
+
+rank = Blueprint("rank", __name__)
+rank_website: Optional[RankWebsite] = None
+app: Optional[Flask] = None
+
+
+@rank.route('/up/<int:page>')
+def rank_up(page: int):
+    global rank_website
+    data = rank_website.get_rank(page, "DESC")
+    return render_template("rank/ranking.html", rank_info=data, ranking_name="高分榜")
+
+
+@rank.route('/down/<int:page>')
+def rank_down(page: int):
+    global rank_website
+    data = rank_website.get_rank(page, "ASC")
+    return render_template("rank/ranking.html", rank_info=data, ranking_name="警示榜")
+
+
+def creat_ranking_website(app_: Flask, db: DB):
+    global rank_website, app
+    if rank_website is None:
+        app = app_
+        app.register_blueprint(rank, url_prefix="/rank")
+        rank_website = RankWebsite(db, app_)

+ 0 - 0
app/rank_web.py → app/rank/web.py


+ 0 - 33
app/rank_views.py

@@ -1,33 +0,0 @@
-from conf import Config
-from flask import render_template, Blueprint, Flask
-from .rank_web import RankWebsite
-from sql.db import DB
-from tool.type_ import Optional
-
-rank_web = Blueprint("rank_web", __name__)
-rank_website: Optional[RankWebsite] = None
-rank_app: Optional[Flask] = None
-
-
-@rank_web.route('/up/<int:page>')
-def rank_up(page: int):
-    global rank_website
-    data = rank_website.get_rank(page, "DESC")
-    return render_template("rank_web/ranking.html", rank_info=data, ranking_name="高分榜")
-
-
-@rank_web.route('/down/<int:page>')
-def rank_down(page: int):
-    global rank_website
-    data = rank_website.get_rank(page, "ASC")
-    return render_template("rank_web/ranking.html", rank_info=data, ranking_name="警示榜")
-
-
-def creat_ranking_website(app: Flask, db: DB):
-    global rank_website, rank_app
-    if rank_website is not None:
-        return rank_website
-    rank_app = app
-    rank_app.register_blueprint(rank_web, url_prefix="/rank")
-    rank_website = RankWebsite(db, rank_app)
-    return rank_website

二进制
app/static/images/favicon.ico


+ 63 - 25
app/static/styles/base.css

@@ -3,19 +3,36 @@ html {
     font-family: 'Noto Sans SC', sans-serif;
     font-family: 'Noto Sans SC', sans-serif;
 }
 }
 
 
+section.top-nav {
+    position: fixed;
+    top: 0;
+    left: 0;
+    width: 100%;
+    height: 80px;
+    vertical-align: center;
+    background-color: rgba(240, 128, 128, 90%);
+    z-index: 10;
+}
+
 ul.top-nav {
 ul.top-nav {
-    background-color: #F08080;
-    text-align: center;
+    display: inline-block;
+    position: absolute;
+    left: 50%;
+    transform: translateX(-50%);
 }
 }
 
 
 li.top-nav-item {
 li.top-nav-item {
     display: inline-block;
     display: inline-block;
-    padding: 20px 20px;
 }
 }
 
 
 a.top-nav-item {
 a.top-nav-item {
+    display: inline-block;
+    padding-left: 20px;
+    padding-right: 20px;
+
     font-size: 20px;
     font-size: 20px;
     font-weight: bold;
     font-weight: bold;
+    line-height: 80px;
 }
 }
 
 
 a.top-nav-item, a.top-nav-item:hover, a.top-nav-item:active, a.top-nav-item:link, a.top-nav-item:visited {
 a.top-nav-item, a.top-nav-item:hover, a.top-nav-item:active, a.top-nav-item:link, a.top-nav-item:visited {
@@ -28,30 +45,38 @@ a.top-nav-item:hover, a.top-nav-item:active {
     color: #800080;
     color: #800080;
 }
 }
 
 
-@keyframes logo-run {
-    0% {
-        left: 0;
-    }
-    50% {
-        left: 100%;
-        transform: translateX(-100%);
-    }
-    100% {
-        left: 0;
-    }
+#start-p {
+    margin-top: 8%;
 }
 }
 
 
-section.logo {
+
+.top-flash-message {
+    display: block;
+    width: 60%;
+    text-align: center;
+
+    border-radius: 15px;
+    background-color: rgba(64, 224, 208);
+
+    font-size: 25px;
+    height: 50px;
+    line-height: 50px;
+    margin: 5px auto;
+}
+
+#top-title {
+    display: inline-block;
+    font-size: 25px;
     position: relative;
     position: relative;
-    height: 200px;
+    left: 3%;
+    line-height: 80px;
+    height: 100%;
+    font-weight: bold;
 }
 }
 
 
-img.logo {
-    position: absolute;
-    left: 0;
-    max-height: 200px;
-    max-width: 200px;
-    animation: logo-run 15s infinite;
+#top-title, #top-title:hover, #top-title:active, #top-title:link, #top-title:visited {
+    text-decoration: underline;
+    color: #FFFFFF;
 }
 }
 
 
 #bottom-nav {
 #bottom-nav {
@@ -60,8 +85,21 @@ img.logo {
     background-color: black;
     background-color: black;
     text-align: center;
     text-align: center;
     vertical-align: center;
     vertical-align: center;
-    height: 5%;
     width: 100%;
     width: 100%;
+    z-index: 10;
+}
+
+@media all and (max-width: 992px) {
+    /* 小屏幕(手机) */
+    #bottom-nav {
+        height: 8%;
+    }
+}
+
+@media not all and (max-width: 992px) {
+    #bottom-nav {
+        height: 5%;
+    }
 }
 }
 
 
 .bottom-nav-item {
 .bottom-nav-item {
@@ -70,12 +108,12 @@ img.logo {
     color: #FFFFFF;
     color: #FFFFFF;
 }
 }
 
 
-a#github-link, a#github-link:hover, a#github-link:active, a#github-link:link, a#github-link:visited {
+#github-link, #github-link:hover, #github-link:active, #github-link:link, #github-link:visited {
     text-decoration: none;
     text-decoration: none;
     color: #FFFFFF;
     color: #FFFFFF;
 }
 }
 
 
-a#github-link:hover, a#github-link:active {
+#github-link:hover, #github-link:active {
     text-decoration: none;
     text-decoration: none;
     color: #800080;
     color: #800080;
 }
 }

+ 42 - 0
app/static/styles/login.css

@@ -0,0 +1,42 @@
+#login_nm_lb, #login_pw_lb, #login_nm, #login_pw {
+    font-size: 20px;
+}
+
+#login_nm_lb, #login_pw_lb {
+    display: inline-block;
+    margin-top: 10px;
+    margin-bottom: 10px;
+}
+
+#login_nm, #login_pw {
+    display: inline-block;
+    margin-top: 10px;
+    margin-bottom: 10px;
+    width: 100%;
+}
+
+#login_submit_div {
+    position: relative;
+    width: 100%;
+    height: 50px;
+}
+
+#login_submit {
+    display: inline-block;
+    margin: 10px auto 10px;
+    font-size: 17px;
+    width: 100px;
+    height: 40px;
+
+    position: absolute;
+    right: 0;
+}
+
+#reg_p {
+    display: inline-block;
+    font-size: 15px;
+
+    position: absolute;
+    right: 110px;
+    bottom: 0;
+}

+ 25 - 0
app/templates/auth/login.html

@@ -0,0 +1,25 @@
+{% extends "base.html" %}
+
+{% block style %}
+    {{ super() }}
+    <link href="{{ url_for('static', filename='styles/login.css') }}" rel="stylesheet">
+{% endblock %}
+
+{% block title %} 用户登录 {% endblock %}
+{% block h1_title %} 用户登录 {% endblock %}
+
+{% block content %}
+    <form method="post" action="{{ url_for('auth.login') }}">
+        {{ form.hidden_tag() }}
+
+        {{ form.name.label(id="login_nm_lb") }}<br>
+        {{ form.name(id="login_nm") }}
+
+        <br>
+        {{ form.passwd.label(id="login_pw_lb") }}<br>
+        {{ form.passwd(id="login_pw") }}
+
+        <br>
+        <div id="login_submit_div"> {{ form.submit(id="login_submit") }} </div>
+    </form>
+{% endblock %}

+ 41 - 13
app/templates/base.html

@@ -35,19 +35,47 @@
 <body>
 <body>
 
 
 {% block nav %}
 {% block nav %}
-    <section class="logo">
-        <img class="logo" src=" {{ url_for('static', filename='images/HGSSystem.png') }} " alt="HGSSystem Logo">
+    <section class="top-nav">
+        <p id="top-title"> HGSSystem-{{ loc }} 在线 </p>
+        <ul class="top-nav">
+            <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('hello.index') }}"> 首页 </a></li>
+            <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('rank.rank_up', page=1) }}"> 高分榜 </a></li>
+            <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('rank.rank_down', page=1) }}"> 警告榜 </a>
+            </li>
+            <li class="top-nav-item"><a class="top-nav-item"> 积分商城 </a></li>
+            <li class="top-nav-item"><a class="top-nav-item"> 新闻 </a></li>
+            {% if current_user.is_authenticated %}
+                <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('auth.logout') }}">
+                    退出: {{ current_user.name }} </a></li>
+            {% else %}
+                <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('auth.login') }}"> 登录 </a></li>
+            {% endif %}
+        </ul>
     </section>
     </section>
-    <ul class="top-nav">
-        <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('hello_web.start') }}"> 首页 </a></li>
-        <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('rank_web.rank_up', page=1) }}"> 高分榜 </a></li>
-        <li class="top-nav-item"><a class="top-nav-item" href="{{ url_for('rank_web.rank_down', page=1) }}"> 警告榜 </a>
-        </li>
-        <li class="top-nav-item"><a class="top-nav-item"> 积分商城 </a></li>
-    </ul>
 {% endblock %}
 {% endblock %}
 
 
+<p id="start-p"></p>  <!-- 占位作用 -->
+
 <article>
 <article>
+    {% block flash %}
+        <section class="top-flash">
+            {% for message in get_flashed_messages() %}
+                <p class="top-flash-message"> {{ message }} </p>
+            {% endfor %}
+            <script>
+                console.log("doneA")
+                setTimeout(function () {
+                    console.log("doneB")
+                    let p_flash = document.querySelectorAll("p.top-flash-message");
+                    for (let i = 0; i < p_flash.length; i += 1) {
+                        p_flash[i].style.display = 'none';
+                        console.log("doneC")
+                    }
+                }, 3000)
+            </script>
+        </section>
+    {% endblock %}
+
     {% block h1_title_ %}
     {% block h1_title_ %}
         <section style="text-align: center">
         <section style="text-align: center">
             <h1 style=";font-size: 35px;font-weight: bold;margin: 3% auto 4%;"> {% block h1_title %} {% endblock %}</h1>
             <h1 style=";font-size: 35px;font-weight: bold;margin: 3% auto 4%;"> {% block h1_title %} {% endblock %}</h1>
@@ -63,10 +91,10 @@
 
 
 <p id="last-p"></p>  <!-- 占位作用 -->
 <p id="last-p"></p>  <!-- 占位作用 -->
 {% block bnav %}
 {% block bnav %}
-    <nav id="bottom-nav">
-        <p class="bottom-nav-item"> 版权归属 (c) SuperHuan<br>在
-            <a id="github-link" href="https://github.com/SuperH-0630/HGSSystem">Github</a>上查看</p>
-    </nav>
+    <footer id="bottom-nav">
+        <p class="bottom-nav-item"> 版权归属 (c) {{ copy_right }}<br>在
+            <a id="github-link" href="{{ github_link }}">Github</a>上查看</p>
+    </footer>
 {% endblock %}
 {% endblock %}
 
 
 </body>
 </body>

+ 0 - 0
app/templates/hello_web/error.html → app/templates/hello/error.html


+ 0 - 0
app/templates/hello_web/start.html → app/templates/hello/index.html


+ 3 - 1
app/templates/hello_web/index.html → app/templates/hello/start.html

@@ -7,6 +7,8 @@
     <link href="{{ url_for('static', filename='styles/index.css') }}" rel="stylesheet">
     <link href="{{ url_for('static', filename='styles/index.css') }}" rel="stylesheet">
 {% endblock %}
 {% endblock %}
 
 
+{# 去除默认的内容 #}
+{% block flash %} {% endblock %}
 {% block nav %} {% endblock %}
 {% block nav %} {% endblock %}
 {% block bnav %} {% endblock %}
 {% block bnav %} {% endblock %}
 {% block h1_title_ %} {% endblock %}
 {% block h1_title_ %} {% endblock %}
@@ -15,7 +17,7 @@
     <section id="base">
     <section id="base">
         <h1 id="title-1"> 欢迎,HGSSystem在线系统 </h1>
         <h1 id="title-1"> 欢迎,HGSSystem在线系统 </h1>
         <h2 id="title-2"> {{ loc }} 站 </h2>
         <h2 id="title-2"> {{ loc }} 站 </h2>
-        <form method="get" action="{{ url_for('hello_web.start') }}">
+        <form method="get" action="{{ url_for('hello.index') }}">
             <input id="btn" type="submit" value="开始">
             <input id="btn" type="submit" value="开始">
         </form>
         </form>
     </section>
     </section>

+ 0 - 0
app/templates/rank_web/rank_macro.html → app/templates/rank/rank_macro.html


+ 1 - 1
app/templates/rank_web/ranking.html → app/templates/rank/ranking.html

@@ -1,5 +1,5 @@
 {% extends "base.html" %}
 {% extends "base.html" %}
-{% import "rank_web/rank_macro.html" as rank %}
+{% import "rank/rank_macro.html" as rank %}
 
 
 {% block style %}
 {% block style %}
     {{ super() }}
     {{ super() }}

+ 4 - 2
app/views.py

@@ -1,6 +1,7 @@
 from flask import Flask
 from flask import Flask
-from .hello_views import creat_hello_website
-from .rank_views import creat_ranking_website
+from app.index.views import creat_hello_website
+from app.rank.views import creat_ranking_website
+from app.auth.views import creat_auth_website
 
 
 from sql.db import DB
 from sql.db import DB
 
 
@@ -8,3 +9,4 @@ from sql.db import DB
 def register(app: Flask, db: DB):
 def register(app: Flask, db: DB):
     creat_hello_website(app)
     creat_hello_website(app)
     creat_ranking_website(app, db)
     creat_ranking_website(app, db)
+    creat_auth_website(app, db)

+ 3 - 3
conf/__init__.py

@@ -3,9 +3,9 @@
 配置文件
 配置文件
 """
 """
 
 
-from font.noto import noto_font
-from picture import head_pic, rank_bg_pic
-from args import p_args
+from .font.noto import noto_font
+from .picture import head_pic, rank_bg_pic
+from .args import p_args
 from .equipment import ConfigCapture
 from .equipment import ConfigCapture
 from .sql import ConfigDatabase
 from .sql import ConfigDatabase
 from .aliyun import ConfigAliyun
 from .aliyun import ConfigAliyun

+ 10 - 0
conf/args.py

@@ -23,6 +23,7 @@ if res is None or res == "False":
     parser.add_argument("--aliyun_key", nargs=1, type=str, help="阿里云认证-KET")
     parser.add_argument("--aliyun_key", nargs=1, type=str, help="阿里云认证-KET")
     parser.add_argument("--aliyun_secret", nargs=1, type=str, help="阿里云认证-SECRET")
     parser.add_argument("--aliyun_secret", nargs=1, type=str, help="阿里云认证-SECRET")
 
 
+    parser.add_argument("--app_secret", nargs=1, type=str, help="系统密钥-SECRET")
     parser.add_argument("--program", nargs=1, type=str, choices=["setup",
     parser.add_argument("--program", nargs=1, type=str, choices=["setup",
                                                                  "garbage",
                                                                  "garbage",
                                                                  "ranking",
                                                                  "ranking",
@@ -50,6 +51,8 @@ if res is None or res == "False":
     if p_args_.aliyun_secret is not None:
     if p_args_.aliyun_secret is not None:
         p_args['aliyun_secret'] = p_args_.aliyun_secret[0]
         p_args['aliyun_secret'] = p_args_.aliyun_secret[0]
 
 
+    if p_args_.app_secret is not None:
+        p_args['app_secret'] = p_args_.app_secret[0].lower()
     if p_args_.program is not None:
     if p_args_.program is not None:
         p_args['program'] = p_args_.program[0].lower()
         p_args['program'] = p_args_.program[0].lower()
     if p_args_.run_type is not None:
     if p_args_.run_type is not None:
@@ -91,6 +94,13 @@ if p_args.get('aliyun_key') is None or p_args.get('aliyun_secret') is None:
             print("阿里云认证错误", file=sys.stderr)
             print("阿里云认证错误", file=sys.stderr)
             exit(1)
             exit(1)
 
 
+if p_args.get('app_secret') is None:
+    res = os.environ.get('HGSSystem_AppSecret')
+    if res is not None:
+        p_args['app_secret'] = res
+    else:
+        p_args['app_secret'] = "HGSSystem"
+
 if p_args.get('run') is None:
 if p_args.get('run') is None:
     res = os.environ.get('HGSSystem_Run')
     res = os.environ.get('HGSSystem_Run')
     if res is not None:
     if res is not None:

+ 0 - 0
conf/font/__init__.py


+ 2 - 1
conf/sys_default.py

@@ -2,7 +2,8 @@ from args import p_args
 
 
 
 
 class ConfigSecretRelease:
 class ConfigSecretRelease:
-    passwd_salt = "HGSSystem"
+    passwd_salt = p_args['app_secret']
+    wtf_secret = p_args['app_secret']
 
 
 
 
 class ConfUserRelease:
 class ConfUserRelease:

+ 10 - 4
main.py

@@ -85,17 +85,23 @@ def main():
         station.mainloop()
         station.mainloop()
     elif program_name == "website":
     elif program_name == "website":
         try:
         try:
-            from app import creat_web
+            from app import creat_web, App
+            from flask import Flask
             from app.views import register
             from app.views import register
         except ImportError:
         except ImportError:
+            raise
             can_not_load("在线排行榜服务")
             can_not_load("在线排行榜服务")
             sys.exit(1)
             sys.exit(1)
 
 
         global app
         global app
-        app = creat_web(mysql)  # 暴露 app 接口
         if __name__ == "__main__":
         if __name__ == "__main__":
-            debug = Config.run_type == 'Debug'
-            app.run(debug=debug)
+            app = creat_web(mysql)  # 暴露 app 接口
+            print("Web 服务启动 访问: http://127.0.0.1:8080/")
+            app.run_waitress(host='0.0.0.0', port="8080")
+            # app.run_flask()
+        else:
+            tmp = creat_web(mysql)  # 暴露 app 接口
+            app = tmp.get_app()
     else:
     else:
         can_not_load(program_name)
         can_not_load(program_name)
         sys.exit(1)
         sys.exit(1)

+ 1 - 0
setup.py

@@ -46,6 +46,7 @@ check_import("qrcode", "qrcode")  # 二维码生成
 check_import("pymysql", "PyMySQL")  # 连接 MySQL服务器
 check_import("pymysql", "PyMySQL")  # 连接 MySQL服务器
 check_import("cryptography", "cryptography")  # 链接 MySQL 服务器时加密
 check_import("cryptography", "cryptography")  # 链接 MySQL 服务器时加密
 check_import("flask", "Flask")  # 网页服务
 check_import("flask", "Flask")  # 网页服务
+check_import("waitress", "waitress")  # waitress 网页服务
 check_import("PIL", "Pillow")  # 图片处理
 check_import("PIL", "Pillow")  # 图片处理
 check_import("numpy", "numpy")  # matplotlib依赖
 check_import("numpy", "numpy")  # matplotlib依赖
 check_import("matplotlib", "matplotlib")  # matplotlib依赖
 check_import("matplotlib", "matplotlib")  # matplotlib依赖

+ 1 - 1
tk_ui/ranking.py

@@ -223,7 +223,7 @@ class RankingStation(RankingStationBase):
         self.rank_title_var = tk.StringVar()
         self.rank_title_var = tk.StringVar()
         self.rank_count = 7  # 一页显示的行数
         self.rank_count = 7  # 一页显示的行数
         self.rank_label = [tk.Label(self.rank_frame) for _ in range(self.rank_count)]
         self.rank_label = [tk.Label(self.rank_frame) for _ in range(self.rank_count)]
-        self.rank_y_height: List[Tuple[float, float]] = []  # rank_web 标签的y坐标信息
+        self.rank_y_height: List[Tuple[float, float]] = []  # rank 标签的y坐标信息
         self.rank_var = [tk.StringVar() for _ in range(self.rank_count)]
         self.rank_var = [tk.StringVar() for _ in range(self.rank_count)]
         self.rank_btn = [tk.Button(self.rank_frame) for _ in range(3)]  # prev, auto, next
         self.rank_btn = [tk.Button(self.rank_frame) for _ in range(3)]  # prev, auto, next