pzx-web-api/app/api/v1/auth.py

31 lines
995 B
Python
Raw Normal View History

2023-08-11 16:36:56 +08:00
from apiflask import APIBlueprint
from app import rpc
2023-08-12 20:00:38 +08:00
from app.api.v1.exception.auth import WechatLoginError, AuthError
2023-08-11 16:36:56 +08:00
from app.api.v1.schema.auth import WechatLoginIn, WechatLoginOut, RefreshTokenIn, RefreshTokenOut
auth = APIBlueprint('auth', __name__)
@auth.post('/wechat_login')
@auth.input(WechatLoginIn)
@auth.output(WechatLoginOut)
2023-08-12 20:23:19 +08:00
@auth.doc(summary='微信登录', description='微信登录')
2023-08-11 16:55:29 +08:00
def wechat_login(json_data):
2023-08-11 16:52:34 +08:00
try:
2023-08-11 16:55:29 +08:00
result = rpc.admin.wechat_login(json_data['code'])
2023-08-11 16:52:34 +08:00
except Exception as e:
2023-08-15 17:49:05 +08:00
raise WechatLoginError(extra_data={'error_docs': str(e)})
2023-08-11 16:36:56 +08:00
return result
@auth.get('/refresh_token')
@auth.input(RefreshTokenIn, location='query')
@auth.output(RefreshTokenOut)
2023-08-12 20:23:19 +08:00
@auth.doc(summary='刷新 Token', description='刷新 Token')
2023-08-11 16:55:29 +08:00
def refresh_token(query_data):
2023-08-11 17:32:48 +08:00
try:
result = rpc.admin.refresh_token(query_data['refresh_token'])
except Exception as e:
2023-08-15 17:49:05 +08:00
raise AuthError(extra_data={'error_docs': str(e)})
2023-08-11 16:36:56 +08:00
return result