109 lines
3.4 KiB
Python
109 lines
3.4 KiB
Python
import flask
|
|
from flask import Flask
|
|
import os
|
|
from .SNAPI import *
|
|
from . import CallServerAPIs
|
|
from . import PyWebPageAPI
|
|
|
|
UA = f"SolianForPythonApp/0.0.1(A) ({PyWebPageAPI.GetDeviceInfo()})"
|
|
|
|
app = Flask(__name__, template_folder='../webfile', static_folder='../webfile/static', static_url_path='/static')
|
|
|
|
@app.errorhandler(500)
|
|
def internal_server_error(error):
|
|
# 返回500错误的HTML页面
|
|
return flask.render_template("/error/500.html", error=error)
|
|
|
|
@app.errorhandler(404)
|
|
def not_found(error):
|
|
# 返回404错误的HTML页面
|
|
return flask.render_template("/error/404.html", error=error), 404
|
|
|
|
@app.errorhandler(403)
|
|
def forbidden(error):
|
|
# 返回403错误的HTML页面
|
|
return flask.render_template("/error/403.html", error=error), 403
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return flask.render_template('index.html')
|
|
|
|
@app.route('/Account')
|
|
def Account():
|
|
return flask.render_template('Account.html')
|
|
|
|
@app.route('/Realm')
|
|
def Realm():
|
|
return flask.render_template('Realm.html')
|
|
|
|
@app.route('/login/')
|
|
def Login():
|
|
return flask.render_template('login.html')
|
|
|
|
@app.route('/Chat')
|
|
def Chat():
|
|
return flask.render_template('Chat.html')
|
|
|
|
@app.route('/api/posts', methods=['GET'])
|
|
def GetPosts():
|
|
data = CallServerAPIs.ActivityAPIs()
|
|
return flask.jsonify({
|
|
"title": data[0]["data"]["title"],
|
|
"description": data[0]["data"]["description"],
|
|
"content": data[0]["data"]["content"],
|
|
"username": data[0]["data"]["publisher"]["name"],
|
|
"nickname": data[0]["data"]["publisher"]["nick"]
|
|
})
|
|
|
|
@app.route('/api/auth/check-account', methods=['GET'])
|
|
def CheckAccount():
|
|
account = flask.request.args.get('account')
|
|
# 调用SNAPI检查账号是否存在
|
|
try:
|
|
global resp
|
|
resp = AccountServices.create_auth_challenge(platform=1,
|
|
device_id=UA,
|
|
device_name=UA,
|
|
account=account)
|
|
return flask.jsonify(resp), 200
|
|
except Exception as e:
|
|
return flask.jsonify({'error': str(e)}), 400
|
|
|
|
@app.route('/api/auth/methods', methods=['GET'])
|
|
def GetAuthMethods():
|
|
account = flask.request.args.get('account')
|
|
# 调用SNAPI获取认证方式
|
|
methods = AccountServices.get_auth_methods(resp['id'])
|
|
# 返回支持的认证方式
|
|
return flask.jsonify([
|
|
methods
|
|
]), 200
|
|
|
|
@app.route('/api/auth/send-verification', methods=['POST'])
|
|
def SendVerification():
|
|
data = flask.request.json
|
|
account = data.get('account')
|
|
method = data.get('method')
|
|
# 这里应该调用实际的API发送验证码
|
|
AccountServices.send_verification_code(account, method)
|
|
return flask.jsonify({'success': True}), 200
|
|
|
|
@app.route('/api/auth/verify-code', methods=['POST'])
|
|
def VerifyCode():
|
|
data = flask.request.json
|
|
account = data.get('account')
|
|
code = data.get('code')
|
|
# 这里应该调用实际的API验证验证码
|
|
# 模拟验证成功
|
|
return flask.jsonify({
|
|
'access_token': 'mock_access_token',
|
|
'refresh_token': 'mock_refresh_token'
|
|
}), 200
|
|
|
|
def AppStart(host: str, port: int):
|
|
"""启动Flask应用"""
|
|
app.run(host=host, port=port, debug=True, use_reloader=False)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host="127.0.0.1", port=5000, debug=True)
|