|
@@ -11,7 +11,7 @@ from typing import Any, Dict
|
|
|
import secrets
|
|
|
from fastapi_login.exceptions import InvalidCredentialsException
|
|
|
from fastapi_login import LoginManager
|
|
|
-from datetime import timedelta,datetime
|
|
|
+from datetime import timedelta,datetime,date
|
|
|
from jose import jwt
|
|
|
from emails.template import JinjaTemplate
|
|
|
from tortoise.queryset import Q
|
|
@@ -70,39 +70,41 @@ async def get_registration(
|
|
|
return {"msg": "please log in", "code": 200}
|
|
|
|
|
|
if get_all:
|
|
|
- inform_list = await User_information.all()
|
|
|
+ inform_list = Registration.all()
|
|
|
else:
|
|
|
- inform_list = await User_information.filter(user_id=user_id).all()
|
|
|
+ inform_list = Registration.filter(user_id=user_id).all()
|
|
|
+
|
|
|
+ if event_id:
|
|
|
+ inform_list = inform_list.filter(event_id=event_id)
|
|
|
+
|
|
|
+ if is_check != None:
|
|
|
+ inform_list = inform_list.filter(reg_confirm=is_check)
|
|
|
+
|
|
|
+ if registration_id:
|
|
|
+ reg_list_tmp = await inform_list.filter(id=registration_id,is_del=0).all()
|
|
|
+ else:
|
|
|
+ reg_list_tmp = await inform_list.filter(is_del=0).all()
|
|
|
+
|
|
|
|
|
|
reg_list = []
|
|
|
|
|
|
- for infor in inform_list:
|
|
|
- if registration_id:
|
|
|
- reg_list_tmp = await Registration.filter(id=registration_id,user_inform_id=infor.id,is_del=0).all()
|
|
|
- else:
|
|
|
- reg_list_tmp = await Registration.filter(user_inform_id=infor.id,is_del=0).all()
|
|
|
+ for infor in reg_list_tmp:
|
|
|
|
|
|
- for reg_obj in reg_list_tmp:
|
|
|
+ try :
|
|
|
reg_data = {
|
|
|
- "Registration_id" : reg_obj.id,
|
|
|
- "event_id" : reg_obj.event_id,
|
|
|
- "user_inform_id" : reg_obj.user_inform_id,
|
|
|
- "reg_confirm" : reg_obj.reg_confirm,
|
|
|
- "create_time" : reg_obj.create_time
|
|
|
+ "Registration_id" : infor.id,
|
|
|
+ "event_id" : infor.event_id,
|
|
|
+ "user_id" : infor.user_id,
|
|
|
+ "reg_confirm" : infor.reg_confirm,
|
|
|
+ "create_time" : infor.create_time
|
|
|
+ }
|
|
|
+ except:
|
|
|
+ reg_data = {
|
|
|
+ "msg" : "fail to get data"
|
|
|
}
|
|
|
- if event_id and reg_data["event_id"] == event_id :
|
|
|
- if is_check != None :
|
|
|
- if reg_obj.reg_confirm == is_check :
|
|
|
- reg_list.append(reg_data)
|
|
|
- else :
|
|
|
- reg_list.append(reg_data)
|
|
|
- elif not event_id:
|
|
|
- if is_check != None :
|
|
|
- if reg_obj.reg_confirm == is_check :
|
|
|
- reg_list.append(reg_data)
|
|
|
- else :
|
|
|
- reg_list.append(reg_data)
|
|
|
|
|
|
+ reg_list.append(reg_data)
|
|
|
+
|
|
|
|
|
|
return {"msg": "success", "code": 200,"registrations":reg_list}
|
|
|
except Exception as e:
|
|
@@ -112,45 +114,115 @@ async def get_registration(
|
|
|
async def input_information(
|
|
|
user_id = Depends(check_token),
|
|
|
name : str = Form(default=''),
|
|
|
+ display_name : str = Form(default=''),
|
|
|
+ birthday : date = Form(default=datetime.now().date()),
|
|
|
gender : str = Form(default=''),
|
|
|
phone : str = Form(default=''),
|
|
|
- email : str = Form(default=''),
|
|
|
- is_default : int = Form(default=0)
|
|
|
+ address : str = Form(default='')
|
|
|
):
|
|
|
try :
|
|
|
if not user_id :
|
|
|
return {"msg": "no access", "code": 200}
|
|
|
|
|
|
- if is_default:
|
|
|
- inform = await User_information.get_or_create(
|
|
|
- user_id=user_id,
|
|
|
- is_default = is_default,
|
|
|
- defaults={
|
|
|
- 'name': name,
|
|
|
- 'gender': gender,
|
|
|
- 'phone': phone,
|
|
|
- 'email': email
|
|
|
- }
|
|
|
- )
|
|
|
- new_inform = inform[0]
|
|
|
- else :
|
|
|
- new_inform = await User_information.create(
|
|
|
- user_id = user_id,
|
|
|
- name = name ,
|
|
|
- gender = gender,
|
|
|
- phone = phone,
|
|
|
- email = email,
|
|
|
- is_default = is_default
|
|
|
- )
|
|
|
-
|
|
|
- return {"msg": "success", "code": 200, "user_inform_id": new_inform.id}
|
|
|
+
|
|
|
+ inform = await User_information.get_or_create(
|
|
|
+ user_id=user_id,
|
|
|
+ defaults={
|
|
|
+ 'name': name,
|
|
|
+ 'birthday' :birthday,
|
|
|
+ 'gender': gender,
|
|
|
+ 'phone': phone,
|
|
|
+ 'address': address
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if display_name != '':
|
|
|
+ user = await User.get(id = user_id)
|
|
|
+ user.username = display_name
|
|
|
+ await user.save()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "user_inform_id": inform[0].id,"is_exist":not inform[1]}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@registration.post("/update_information")
|
|
|
+async def update_information(
|
|
|
+ user_id = Depends(check_token),
|
|
|
+ name : str = Form(default=''),
|
|
|
+ display_name : str = Form(default=''),
|
|
|
+ birthday : date = Form(default=datetime.now().date()),
|
|
|
+ gender : str = Form(default=''),
|
|
|
+ phone : str = Form(default=''),
|
|
|
+ address : str = Form(default='')
|
|
|
+):
|
|
|
+ try :
|
|
|
+ if not user_id :
|
|
|
+ return {"msg": "no access", "code": 200}
|
|
|
+
|
|
|
+ infor = await User_information.get(user_id = user_id)
|
|
|
+ user = await User.get(id = user_id)
|
|
|
+
|
|
|
+ if name != '':
|
|
|
+ infor.name = name
|
|
|
+
|
|
|
+ if birthday != datetime.now().date():
|
|
|
+ infor.birthday = birthday
|
|
|
+
|
|
|
+ if gender != '':
|
|
|
+ infor.gender = gender
|
|
|
+
|
|
|
+ if phone != '':
|
|
|
+ infor.phone = phone
|
|
|
+
|
|
|
+ if address != '':
|
|
|
+ infor.address = address
|
|
|
+
|
|
|
+ if display_name != '':
|
|
|
+ user.username = display_name
|
|
|
+
|
|
|
+ await infor.save()
|
|
|
+ await user.save()
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200, "user_inform_id": infor.id}
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
+@registration.get("/get_user_information")
|
|
|
+async def get_user_information(
|
|
|
+ user_id = Depends(check_token)
|
|
|
+):
|
|
|
+ try:
|
|
|
+ if not user_id :
|
|
|
+ return {"msg": "no access", "code": 200}
|
|
|
+
|
|
|
+ try:
|
|
|
+ infor = await User_information.get(user_id=user_id)
|
|
|
+ except:
|
|
|
+ return {"msg": "no user information", "code": 200}
|
|
|
+
|
|
|
+ user_obj = await User.get(id = user_id)
|
|
|
+
|
|
|
+ user_inform = {
|
|
|
+ "user_id" : infor.user_id,
|
|
|
+ "display_name" : user_obj.username,
|
|
|
+ "name" : infor.name,
|
|
|
+ "birthday" : infor.birthday,
|
|
|
+ "gender" : infor.gender,
|
|
|
+ "phone" : infor.phone,
|
|
|
+ "address" : infor.address,
|
|
|
+ "email" : user_obj.email
|
|
|
+ }
|
|
|
+
|
|
|
+ return {"msg":"success","code":200,"user_inform": user_inform}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
|
|
|
@registration.post("/input_registration")
|
|
|
async def input_registration(
|
|
|
user_id = Depends(check_token),
|
|
|
- user_inform_id : int= Form(default=0),
|
|
|
event_id : int = Form(default=0)
|
|
|
):
|
|
|
try :
|
|
@@ -162,10 +234,14 @@ async def input_registration(
|
|
|
|
|
|
# if check_if_id_exeit(Class_list,event_id):
|
|
|
# return {"msg": "no class list", "code": 200}
|
|
|
+ try:
|
|
|
+ await User_information.get(user_id=user_id)
|
|
|
+ except:
|
|
|
+ return {"msg": "no user information", "code": 200}
|
|
|
|
|
|
new_registration = await Registration.create(
|
|
|
event_id = event_id,
|
|
|
- user_inform_id = user_inform_id,
|
|
|
+ user_id = user_id,
|
|
|
reg_confirm = 0,
|
|
|
is_del = 0 ,
|
|
|
create_time = datetime.now()
|
|
@@ -191,12 +267,37 @@ async def confirm_reg(
|
|
|
except Exception as e:
|
|
|
return {"msg": str(e), "code": 500}
|
|
|
|
|
|
+@registration.post("/recover_registration")
|
|
|
+async def delete_registration(
|
|
|
+ user_id = Depends(check_token),
|
|
|
+ event_id : int = 0
|
|
|
+):
|
|
|
+ try:
|
|
|
+
|
|
|
+ if not user_id :
|
|
|
+ return {"msg": "please log in", "code": 200}
|
|
|
+
|
|
|
+ registration_obj = await Registration.get(event_id=event_id,user_id=user_id)
|
|
|
+
|
|
|
+ registration_obj.is_del = 0
|
|
|
+
|
|
|
+ await registration_obj.save()
|
|
|
+
|
|
|
+ return {"msg": "success", "code": 200}
|
|
|
+ except Exception as e:
|
|
|
+ return {"msg": str(e), "code": 500}
|
|
|
+
|
|
|
@registration.post("/delete_registration")
|
|
|
async def delete_registration(
|
|
|
- registration_id : int
|
|
|
+ user_id = Depends(check_token),
|
|
|
+ event_id : int = 0
|
|
|
):
|
|
|
try:
|
|
|
- registration_obj = await Registration.get(id=registration_id)
|
|
|
+
|
|
|
+ if not user_id :
|
|
|
+ return {"msg": "please log in", "code": 200}
|
|
|
+
|
|
|
+ registration_obj = await Registration.get(event_id=event_id,user_id=user_id)
|
|
|
|
|
|
registration_obj.is_del = 1
|
|
|
|