from flask import Flask
from flask_login import LoginManager, login_required

from User import query_user, User
from bugsearch import bugsearch
from login import login
from logout import logout
from upload import bugupload
from bugdetails import bugdetails
from administer import bugadminister
from buglist import buglist

app = Flask(__name__)
app.secret_key = '258258'
app.register_blueprint(bugupload.bugupload)
app.register_blueprint(bugdetails.bugdetails)
app.register_blueprint(bugadminister.bugadminister)
app.register_blueprint(buglist.buglist)
app.register_blueprint(login.login)
app.register_blueprint(logout.logout)
app.register_blueprint(bugsearch.bugsearch)

login_manager = LoginManager()  # 实例化登录管理对象
login_manager.login_view = '/'  # 设置用户登录视图函数 endpoint
login_manager.init_app(app)  # 初始化应用

@login_manager.user_loader
def load_user(user_id):
    if query_user(user_id) is not None:
        curr_user = User()
        curr_user.id = user_id
        return curr_user

@app.route("/")
def index():
    return login.index()

@app.route('/bugdetails/<bugid>')
@login_required
def bugdetails(bugid):
    return bugdetails.index(bugid)

if __name__ == "__main__":
    # app.run(host="0.0.0.0",port=80)
    app.run(debug=True)

