diff --git a/config.ini b/config.ini index ec98b57..792a84a 100644 --- a/config.ini +++ b/config.ini @@ -1,4 +1,11 @@ [app] NAME=APP_NAME SECRET_KEY=SOME_RANDOM_STRING -SQLALCHEMY_DATABASE_URI=sqlite:///sqlite.db \ No newline at end of file +SQLALCHEMY_DATABASE_URI=sqlite:///sqlite.db + +[network] +PROXY=http://127.0.0.1:7890 + +[gpt] +SECRET_KEY= +MODEL_NAME=gpt-3.5-turbo \ No newline at end of file diff --git a/project/auth.py b/project/auth.py index 44a4c9f..021f0d1 100644 --- a/project/auth.py +++ b/project/auth.py @@ -31,7 +31,7 @@ def login_post(): # if the above check passes, then we know the user has the right credentials login_user(user, remember=remember) - return redirect(url_for('main.profile')) + return redirect(url_for('main.index')) @auth.route('/signup') @@ -67,7 +67,7 @@ def signup_post(): isActivated=False) # first user is always admin - if not db.session.query(User).count(): + if not User.query.count(): new_user.role='admin' new_user.isActivated=True # add the new user to the database diff --git a/project/main.py b/project/main.py index b62f914..cb85396 100644 --- a/project/main.py +++ b/project/main.py @@ -1,19 +1,53 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, request, flash, redirect, url_for from flask_login import login_required, current_user, login_manager +from .models import User main = Blueprint('main', __name__) @main.route('/') def index(): - if current_user.is_authenticated: - name = current_user.name - else: - name = '游客' - return render_template('index.html', username=name, is_authenticated=current_user.is_authenticated) + return render_template('index.html', user=current_user) @main.route('/profile') @login_required def profile(): - return render_template('profile.html', username=current_user.name, isActivated=current_user.isActivated) + if current_user.role == "admin": + return render_template('profile.html', user=current_user, accounts=User.query.all()) + return render_template('profile.html', user=current_user) + + +@main.route('/manage') +@login_required +def manage(): + if current_user.role == "admin": + accountid = request.args.get('id') + if accountid: + accounts = User.query.filter_by(id=accountid) + else: + accounts = User.query + if accounts: + return render_template('manage.html', user=current_user, accounts=accounts) + else: + flash("无此用户id!") + return redirect(request.referrer if request.referrer else url_for('main.index')) + + flash("您无权管理其他账户") + return redirect(url_for('main.index')) + + +@main.route('/manage', methods=['POST']) +@login_required +def manage_post(): + if current_user.role == "admin": + return "manage for account id "+str(request.args.get('id')) + + flash("您无权管理其他账户") + return redirect(url_for('main.index')) + + +@main.route('/chat') +@login_required +def chat(): + return "暂未实现" diff --git a/project/templates/base.html b/project/templates/base.html index 10e89e9..3a80e0b 100644 --- a/project/templates/base.html +++ b/project/templates/base.html @@ -27,10 +27,10 @@
@@ -42,6 +42,20 @@ {% endblock %} + +