dev@locazia: closer to finish autorization
This commit is contained in:
1 parent
0d83eaeb91
commit
a0489a7383
7 files changed
+34
-3
No files matched your search
@@ -11,13 +11,17 @@ app.register_middleware(attach_user_to_request, "request")
|
||||
app.register_middleware(close_db_session, "response")
|
||||
|
||||
from app.api.routes._index import s_index
|
||||
from app.api.routes._system import s_api_system_version
|
||||
from app.api.routes.auth import s_api_v1_auth_twa
|
||||
from app.api.routes.tonconnect import s_api_tonconnect_manifest
|
||||
from app.api.routes.node_storage import s_api_v1_storage_post, s_api_v1_storage_get
|
||||
from app.api.routes.account import s_api_v1_account_get
|
||||
from app.api.routes.custodial import s_api_v1_custodial_upload_content
|
||||
|
||||
app.add_route(s_index, "/")
|
||||
|
||||
app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"])
|
||||
|
||||
app.add_route(s_api_tonconnect_manifest, "/api/tonconnect-manifest.json")
|
||||
|
||||
app.add_route(s_api_v1_auth_twa, "/api/v1/auth.twa", methods=["POST", "OPTIONS"])
|
||||
@@ -25,6 +29,8 @@ app.add_route(s_api_v1_auth_twa, "/api/v1/auth.twa", methods=["POST", "OPTIONS"]
|
||||
app.add_route(s_api_v1_storage_post, "/api/v1/storage", methods=["POST", "OPTIONS"])
|
||||
app.add_route(s_api_v1_storage_get, "/api/v1/storage/<file_hash>", methods=["GET", "OPTIONS"])
|
||||
|
||||
app.add_route(s_api_v1_account_get, "/api/v1/account", methods=["GET", "OPTIONS"])
|
||||
|
||||
app.add_route(s_api_v1_custodial_upload_content, "/api/v1/custodial.uploadContent", methods=["POST", "OPTIONS"])
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ async def try_authorization(request):
|
||||
|
||||
|
||||
async def attach_user_to_request(request):
|
||||
request.ctx.user = None
|
||||
request.ctx.user_key = None
|
||||
request.ctx.db_session = Session()
|
||||
await try_authorization(request)
|
||||
|
||||
|
||||
@@ -4,4 +4,3 @@ from sanic import response
|
||||
async def s_index(request):
|
||||
return response.text("OK")
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
from sanic import response
|
||||
import subprocess
|
||||
|
||||
|
||||
def get_git_info():
|
||||
branch_name = subprocess.check_output(["git", "branch", "--show-current"]).decode('utf-8').strip()
|
||||
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode('utf-8').strip()
|
||||
return branch_name, commit_hash
|
||||
|
||||
|
||||
async def s_api_system_version(request):
|
||||
branch_name, commit_hash = get_git_info()
|
||||
return response.json({
|
||||
"codebase_hash": commit_hash,
|
||||
"codebase_branch": branch_name,
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
from sanic import response
|
||||
|
||||
|
||||
async def s_api_v1_account_get(request):
|
||||
if not request.ctx.user:
|
||||
return response.json({"error": "User not found"}, status=400)
|
||||
|
||||
return response.json(request.ctx.user.json_format())
|
||||
@@ -1,7 +1,6 @@
|
||||
from sanic import response
|
||||
from app.core._config import TELEGRAM_API_KEY
|
||||
from app.core.models.user import User
|
||||
from app.core.logger import make_log
|
||||
from aiogram.utils.web_app import safe_parse_webapp_init_data
|
||||
from datetime import datetime
|
||||
|
||||
@@ -37,7 +36,6 @@ async def s_api_v1_auth_twa(request):
|
||||
known_user = request.ctx.db_session.query(User).filter(User.telegram_id == twa_data.user.id).first()
|
||||
assert known_user, "User not created"
|
||||
|
||||
|
||||
new_user_key = await known_user.create_api_token_v1(request.ctx.db_session, "USER_API_V1")
|
||||
return response.json({
|
||||
'user': known_user.json_format(),
|
||||
|
||||
Reference in new issue
Block a user