|
@@ -22,17 +22,23 @@ router = APIRouter(
|
|
|
@web_try()
|
|
|
@sxtimeit
|
|
|
def switch_project(switch: schemas.SwitchProject):
|
|
|
+ role_id = 0
|
|
|
if switch.project_id == special_project_id and super_admin_role in switch.role_ids:
|
|
|
- return {"role_id": 1}
|
|
|
+ role_id = 1
|
|
|
elif switch.project_id == special_project_id:
|
|
|
- return {"role_id": 3}
|
|
|
+ role_id = 3
|
|
|
else:
|
|
|
- return {"role_id": 5}
|
|
|
+ role_id = 5
|
|
|
+ token_data = {"user_id": switch.user_id,"user_name":switch.user_name,"project_id": switch.project_id, "role_id": role_id}
|
|
|
+ token_data_str =json.dumps(token_data)
|
|
|
+ access_token = encode_base64(token_data_str).replace('\n','')
|
|
|
+ return {"access_token": access_token, "token_type": "Bearer", "role_id": role_id}
|
|
|
+
|
|
|
|
|
|
@router.post("/login",response_model=schemas.Token)
|
|
|
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
|
|
|
user_id, project_id = form_data.username, form_data.password
|
|
|
- token_data = {"user_id": user_id,"user_name":"admin","project_id": project_id, "role_id": 1}
|
|
|
+ token_data = {"user_id": user_id,"user_name":"刘涛","project_id": project_id, "role_id": 1}
|
|
|
token_data_str =json.dumps(token_data)
|
|
|
access_token = encode_base64(token_data_str).replace('\n','')
|
|
|
return {"access_token": access_token, "token_type": "bearer"}
|