This repository has been archived on 2023-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
web-gpt/project/main.py
2023-04-01 19:38:43 +08:00

54 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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():
return render_template('index.html', user=current_user)
@main.route('/profile')
@login_required
def profile():
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 "暂未实现"