diff --git a/core/SNAPI/AccountServices.py b/core/SNAPI/AccountServices.py index a9142cd..38c9645 100644 --- a/core/SNAPI/AccountServices.py +++ b/core/SNAPI/AccountServices.py @@ -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 diff --git a/core/WebApp.py b/core/WebApp.py index 8de7e76..9c87d89 100644 --- a/core/WebApp.py +++ b/core/WebApp.py @@ -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) \ No newline at end of file + app.run(host="127.0.0.1", port=5000, debug=True) diff --git a/webfile/Account.html b/webfile/Account.html index 3ff7672..0384ac5 100644 --- a/webfile/Account.html +++ b/webfile/Account.html @@ -27,7 +27,10 @@
这里是账户设置界面。
+