|
@@ -1,3 +1,5 @@
|
|
|
+import json
|
|
|
+
|
|
|
from fastapi_login import LoginManager
|
|
|
from fastapi import APIRouter, Form, Depends, HTTPException, File, UploadFile
|
|
|
from typing import List,Optional,Union
|
|
@@ -132,13 +134,23 @@ async def input_information(
|
|
|
gender : str = Form(default=''),
|
|
|
phone : str = Form(default=''),
|
|
|
address : str = Form(default=''),
|
|
|
- user_id = Depends(check_token)
|
|
|
+ user_id = Depends(check_token),
|
|
|
+ position: str = Form(...),
|
|
|
):
|
|
|
try :
|
|
|
if not user_id :
|
|
|
return {"msg": "no access", "code": 200}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ position_list = json.loads(position)
|
|
|
+ d = {"學員":0,"開課工藝家":0,"其他":0}
|
|
|
+ if 1 in position_list:
|
|
|
+ d["學員"] = 1
|
|
|
+ if 2 in position_list:
|
|
|
+ d["開課工藝家"] = 1
|
|
|
+ if 3 in position_list:
|
|
|
+ d["其他"] = 1
|
|
|
+ print(d)
|
|
|
+
|
|
|
inform = await User_information.get_or_create(
|
|
|
user_id=user_id,
|
|
|
defaults={
|
|
@@ -146,7 +158,8 @@ async def input_information(
|
|
|
'birthday' :birthday,
|
|
|
'gender': gender,
|
|
|
'phone': phone,
|
|
|
- 'address': address
|
|
|
+ 'address': address,
|
|
|
+ 'position': d,
|
|
|
}
|
|
|
)
|
|
|
|
|
@@ -169,7 +182,8 @@ async def update_information(
|
|
|
gender : str = Form(default=''),
|
|
|
phone : str = Form(default=''),
|
|
|
address : str = Form(default=''),
|
|
|
- user_id = Depends(check_token)
|
|
|
+ user_id = Depends(check_token),
|
|
|
+ position : str = Form(default=''),
|
|
|
):
|
|
|
try :
|
|
|
if not user_id :
|
|
@@ -177,6 +191,14 @@ async def update_information(
|
|
|
|
|
|
infor = await User_information.get(user_id = user_id)
|
|
|
user = await User.get(id = user_id)
|
|
|
+ position_list = json.loads(position)
|
|
|
+ d = {"學員":0,"開課工藝家":0,"其他":0}
|
|
|
+ if 1 in position_list:
|
|
|
+ d["學員"] = 1
|
|
|
+ if 2 in position_list:
|
|
|
+ d["開課工藝家"] = 1
|
|
|
+ if 3 in position_list:
|
|
|
+ d["其他"] = 1
|
|
|
|
|
|
if name != '':
|
|
|
infor.name = name
|
|
@@ -195,6 +217,8 @@ async def update_information(
|
|
|
|
|
|
if user_name != '':
|
|
|
user.username = user_name
|
|
|
+ if position != '':
|
|
|
+ infor.position = d
|
|
|
|
|
|
await infor.save()
|
|
|
await user.save()
|
|
@@ -239,13 +263,14 @@ async def get_user_information(
|
|
|
user_inform["address"] = inform.address
|
|
|
user_inform["msg"] = "user information exist"
|
|
|
user_inform["exist"] = True
|
|
|
+ user_inform["position"] = inform.position
|
|
|
|
|
|
except:
|
|
|
user_inform["msg"] = "no user information"
|
|
|
user_inform["exist"] = False
|
|
|
|
|
|
user_inform_list.append(user_inform)
|
|
|
-
|
|
|
+ print(user_inform_list)
|
|
|
|
|
|
return {"msg":"success","code":200,"user_inform": user_inform_list}
|
|
|
except Exception as e:
|