更新代码

This commit is contained in:
2025-09-14 18:05:12 +08:00
parent ba18997410
commit d83f30c07b
4 changed files with 476 additions and 9 deletions

View File

@@ -218,7 +218,28 @@ def create_auth_challenge(
request_body["scopes"] = scopes
return _make_request('POST', url, headers, request_body=request_body)
def perform_auth_challenge(
def get_auth_methods(
account: str,
) -> dict:
"""获取认证方式"""
url = f"{DOMAIN}/api/auth/challenge/{account}/factors"
headers = {
'accept': 'application/json',
}
return _make_request('GET', url, headers)
def send_verification_code(
id: str,
factor_id: str,
) -> dict:
"""发送验证码"""
url = f"{DOMAIN}/api/auth/challenge/{id}/factors/{factor_id}"
headers = {
'accept': 'application/json',
}
return _make_request('POST', url, headers)
def perform_auth_challenge_password(
challenge_id: str,
factor_id: str,
password: str

View File

@@ -1,29 +1,32 @@
import flask
from flask import Flask
import os
from .SNAPI import *
from . import CallServerAPIs
from . import PyWebPageAPI
app = Flask(__name__)
UA = f"SolianForPythonApp/0.0.1(A) ({PyWebPageAPI.GetDeviceInfo()})"
app = flask.Flask(__name__, template_folder='../webfile', static_folder='../webfile/static', static_url_path='/static')
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,static_url_path='/static')
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,static_url_path='/static'),404
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,static_url_path='/static'),403
return flask.render_template("/error/403.html", error=error), 403
@app.route('/')
def index():
return flask.render_template('index.html',static_url_path='/static')
return flask.render_template('index.html')
@app.route('/Account')
def Account():
@@ -33,14 +36,73 @@ def Account():
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)
app.run(host="127.0.0.1", port=5000, debug=True)