Commit d3b3699e authored by lcn's avatar lcn

调整为公共登录

parent 04552a63
...@@ -21,7 +21,7 @@ def authorized(): ...@@ -21,7 +21,7 @@ def authorized():
# run some method that checks the request # run some method that checks the request
# for the client's authorization status # for the client's authorization status
is_authorized = await user_product_auth.check_user_auth(request) is_authorized = await user_product_auth.check_user_auth(request)
if is_authorized: if is_authorized:
# the user is authorized. # the user is authorized.
# run the handler method and return the response # run the handler method and return the response
...@@ -30,9 +30,9 @@ def authorized(): ...@@ -30,9 +30,9 @@ def authorized():
else: else:
# the user is not authorized. # the user is not authorized.
return json({'status': 'not_authorized'}, 403) return json({'status': 'not_authorized'}, 403)
return decorated_function return decorated_function
return decorator return decorator
...@@ -46,54 +46,54 @@ def is_need_verify(path): ...@@ -46,54 +46,54 @@ def is_need_verify(path):
log.info("is_or_not_need_verify path:%s", path) log.info("is_or_not_need_verify path:%s", path)
if "swagger" in path: if "swagger" in path:
return False return False
if re.match("^/unify-api/auth/?$", path): if re.match("^/unify-api/auth/?$", path):
log.info("auth not need verify") log.info("auth not need verify")
return False return False
if re.match("^/unify-api/upgrade/?", path): if re.match("^/unify-api/upgrade/?", path):
log.info("upgrade device not need verify") log.info("upgrade device not need verify")
return False return False
if re.match("^/unify-api/uassistant/?", path): if re.match("^/unify-api/uassistant/?", path):
log.info("uassistant not need verify") log.info("uassistant not need verify")
return False return False
if re.match("^/unify-api/device-cloud/?", path): if re.match("^/unify-api/device-cloud/?", path):
log.info("device_cloud not need verify") log.info("device_cloud not need verify")
return False return False
if re.match("^/unify-api/users/current-user-info/send-sms?", path): if re.match("^/unify-api/users/current-user-info/send-sms?", path):
log.info("send-sms not need verify") log.info("send-sms not need verify")
return False return False
if re.match("^/unify-api/users/current-user-info/save-userinfo?", path): if re.match("^/unify-api/users/current-user-info/save-userinfo?", path):
log.info("save-userinfo not need verify") log.info("save-userinfo not need verify")
return False return False
if re.match("^/unify-api/users/current-user-info/auth-phone?", path): if re.match("^/unify-api/users/current-user-info/auth-phone?", path):
log.info("auth-phone not need verify") log.info("auth-phone not need verify")
return False return False
if re.match("^/unify-api/users/current-user-info/back-password?", path): if re.match("^/unify-api/users/current-user-info/back-password?", path):
log.info("back-password not need verify") log.info("back-password not need verify")
return False return False
if re.match("^/unify-api/users/current-user-info/update-password?", path): if re.match("^/unify-api/users/current-user-info/update-password?", path):
log.info("update-password not need verify") log.info("update-password not need verify")
return False return False
if re.match("^/api/common/wechat/mp", path): if re.match("^/api/common/wechat/mp", path):
log.info("/api/common/wechat/mp not need verify") log.info("/api/common/wechat/mp not need verify")
return False return False
if re.search("/qk-website", path): if re.search("/qk-website", path):
log.info(f"{path} not need verify") log.info(f"{path} not need verify")
return False return False
# if re.match("^/unify-api/users/logout/user-logout/?$", path): # if re.match("^/unify-api/users/logout/user-logout/?$", path):
# log.info("logout not need verify") # log.info("logout not need verify")
# return False # return False
return True return True
...@@ -119,11 +119,12 @@ async def auth_verify(request): ...@@ -119,11 +119,12 @@ async def auth_verify(request):
# 直接将请求转发到auth # 直接将请求转发到auth
resp_str, status = await AioHttpUtils().post( resp_str, status = await AioHttpUtils().post(
SETTING.verify_url, SETTING.verify_url,
data={}, data={"db": SETTING.mysql_db},
timeout=50, timeout=50,
headers={"Authorization": f"Bearer {token}"} headers={"Authorization": f"Bearer {token}"}
) )
log.info(f"request auth_url resp_str={resp_str} {type(resp_str)} status={status}") log.info(
f"request auth_url resp_str={resp_str} {type(resp_str)} status={status}")
if status == 200: if status == 200:
payload = ujson.loads(resp_str) payload = ujson.loads(resp_str)
setattr(request.ctx, "user_id", payload["user_id"]) setattr(request.ctx, "user_id", payload["user_id"])
...@@ -178,7 +179,7 @@ async def auth_verify_cid(request): ...@@ -178,7 +179,7 @@ async def auth_verify_cid(request):
# 3. 如果参数中包含cid或者cids,cid_list # 3. 如果参数中包含cid或者cids,cid_list
if cid or cids or cid_list: if cid or cids or cid_list:
user_id = request.ctx.user_id user_id = request.ctx.user_id
proxy_id = args.get("proxy_id") proxy_id = args.get("proxy_id")
# 2.2 从mysql获取 # 2.2 从mysql获取
if proxy_id: if proxy_id:
...@@ -190,7 +191,7 @@ async def auth_verify_cid(request): ...@@ -190,7 +191,7 @@ async def auth_verify_cid(request):
# if cid_info: # if cid_info:
# cid_res_list = [int(cid) for cid in cid_info.get("product")] # cid_res_list = [int(cid) for cid in cid_info.get("product")]
# else: # else:
# cid_res_list = await get_cids(user_id, product) # cid_res_list = await get_cids(user_id, product)
# 2.3 参数中的cid_args # 2.3 参数中的cid_args
cid_args = None cid_args = None
......
...@@ -20,7 +20,8 @@ async def wechat_login(args, host): ...@@ -20,7 +20,8 @@ async def wechat_login(args, host):
"user_info": args.get("user_info"), "user_info": args.get("user_info"),
"client_name": args.get("client_name"), "client_name": args.get("client_name"),
"host": host, "host": host,
"product": args.get("product") "product": args.get("product"),
"db": SETTING.mysql_db
} }
try: try:
...@@ -45,7 +46,8 @@ async def app_login(args, host): ...@@ -45,7 +46,8 @@ async def app_login(args, host):
"client_name": args.get("client_name"), "client_name": args.get("client_name"),
"unionid": args.get("unionid"), "unionid": args.get("unionid"),
"host": host, "host": host,
"product": args.get("product") "product": args.get("product"),
"db": SETTING.mysql_db
} }
if not args.get("unionid"): if not args.get("unionid"):
return 401, {"code": 40001, "data": None, "message": "unionid is None"} return 401, {"code": 40001, "data": None, "message": "unionid is None"}
...@@ -72,6 +74,7 @@ async def web_login(args, host): ...@@ -72,6 +74,7 @@ async def web_login(args, host):
"code": args['code'], "code": args['code'],
"client_name": args.get("client_name"), "client_name": args.get("client_name"),
"host": host, "host": host,
"db": SETTING.mysql_db
} }
try: try:
# auth_url = "http://0.0.0.0:9000/unify-api/auth" # auth_url = "http://0.0.0.0:9000/unify-api/auth"
...@@ -110,7 +113,8 @@ async def third_login(args, host): ...@@ -110,7 +113,8 @@ async def third_login(args, host):
"password": password, "password": password,
"client_name": args.get("client_name"), "client_name": args.get("client_name"),
"host": host, "host": host,
"product": args.get("product") "product": args.get("product"),
"db": SETTING.mysql_db
} }
try: try:
log.info( log.info(
...@@ -148,6 +152,7 @@ async def web_third_login(args, host): ...@@ -148,6 +152,7 @@ async def web_third_login(args, host):
"password": password, "password": password,
"client_name": args.get("client_name"), "client_name": args.get("client_name"),
"host": host, "host": host,
"db": SETTING.mysql_db
} }
try: try:
log.info( log.info(
...@@ -197,6 +202,7 @@ async def validation_login(args, host): ...@@ -197,6 +202,7 @@ async def validation_login(args, host):
"user_id": user["user_id"], "user_id": user["user_id"],
"client_name": client_name, "client_name": client_name,
"host": host, "host": host,
"db": SETTING.mysql_db
} }
try: try:
log.info(SETTING.auth_url, f"request auth_url={SETTING.auth_url} " log.info(SETTING.auth_url, f"request auth_url={SETTING.auth_url} "
......
...@@ -28,7 +28,7 @@ class AuthView(HTTPMethodView): ...@@ -28,7 +28,7 @@ class AuthView(HTTPMethodView):
resp_str, status_code = await AioHttpUtils().post( resp_str, status_code = await AioHttpUtils().post(
SETTING.auth_url, SETTING.auth_url,
{"user_name": "balabala", "password": "balabala", {"user_name": "balabala", "password": "balabala",
"client_name": client_name}, "client_name": client_name, "db": SETTING.mysql_db},
timeout=50, timeout=50,
) )
print(f"resp_str = {resp_str} status={status_code}") print(f"resp_str = {resp_str} status={status_code}")
......
...@@ -152,7 +152,8 @@ async def post_save_userinfo(request, body: SaveUserReq): ...@@ -152,7 +152,8 @@ async def post_save_userinfo(request, body: SaveUserReq):
"phone": phone, "phone": phone,
"client_name": "validation", "client_name": "validation",
"host": request.host, "host": request.host,
"user_id": user["user_id"] "user_id": user["user_id"],
"db": SETTING.mysql_db
} }
resp_str, status = await AioHttpUtils().post( resp_str, status = await AioHttpUtils().post(
SETTING.auth_url, SETTING.auth_url,
......
...@@ -54,8 +54,13 @@ async def get_user_logout(request) -> Success: ...@@ -54,8 +54,13 @@ async def get_user_logout(request) -> Success:
# await jwt_utils.store_token_blacklist(token) # await jwt_utils.store_token_blacklist(token)
try: try:
log.info(f"request logout_url={SETTING.logout_url}") log.info(f"request logout_url={SETTING.logout_url}")
resp_str, status = await AioHttpUtils().get( request_body = {
"db": SETTING.mysql_db
}
resp_str, status = await AioHttpUtils().post(
SETTING.logout_url, SETTING.logout_url,
request_body,
timeout=50,
headers={"Authorization": f"Bearer {token}"}, headers={"Authorization": f"Bearer {token}"},
) )
log.info(f"request auth_url resp_str={resp_str} status={status}") log.info(f"request auth_url resp_str={resp_str} status={status}")
......
...@@ -21,7 +21,11 @@ class RefreshView(HTTPMethodView): ...@@ -21,7 +21,11 @@ class RefreshView(HTTPMethodView):
status=200) status=200)
resp, status_code = await AioHttpUtils().post( resp, status_code = await AioHttpUtils().post(
SETTING.refresh_token_url, SETTING.refresh_token_url,
{"refresh_token": refresh_token, "client_name": client_name}, {
"refresh_token": refresh_token,
"client_name": client_name,
"db": SETTING.mysql_db
},
timeout=50, timeout=50,
headers={"Authorization": f"Bearer {token}"} headers={"Authorization": f"Bearer {token}"}
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment