54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
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 "暂未实现"
|