Free and open source ticket system written in python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 5edd527aaba4e33b526f04f58d0db2b8a4ef278e 55 lines 1.9 kB view raw
1import requests 2from django.conf import settings 3from .models import FblAccount 4 5def fbl_auth_request_code(badge_number: int, dob: str) -> bool: 6 res = requests.post(f'{settings.FBL_AUTH_SERVER}/auth/get-code', data={ 7 "badge": badge_number, 8 "password": dob 9 }) 10 if res.status_code != 201: 11 print(res.status_code) 12 return False 13 return True 14 15def fbl_auth_validate_code(badge_number: str, dob: str, validation_code: str) -> str | None: 16 res = requests.post(f'{settings.FBL_AUTH_SERVER}/auth/signin', json={ 17 "badge": badge_number, 18 "password": dob, 19 "code": validation_code 20 }) 21 if res.status_code != 201: 22 print(res.status_code) 23 return None 24 25 return res.json()["accessToken"] 26 27def fbl_auth_get_account(jwt_token: str) -> dict[str, str] | None: 28 res = requests.get(f'{settings.FBL_AUTH_SERVER}/attendees/me', headers={ 29 "Authorization": f"Bearer {jwt_token}" 30 }) 31 if res.status_code != 200: 32 print(res.status_code) 33 return None 34 35 return res.json() 36 37def get_or_create_account(account_info: dict[str, str]) -> FblAccount: 38 """Get or create a FblAccount object based on the account info""" 39 if FblAccount.objects.filter(account_id=account_info["account_id"]).exists(): 40 # Get existing user and update status 41 user = FblAccount.objects.get(account_id=account_info["account_id"]) 42 user.status = account_info["status"] 43 user.save() 44 return user 45 46 # Create new user with (generic) username 47 user = FblAccount.create_user(account_info["username"]) 48 return FblAccount.objects.create( 49 user=user, 50 badge_number=account_info["badge"], 51 account_id=account_info["account_id"], 52 status=account_info["status"], 53 username=account_info["username"], 54 tags_secured=','.join(account_info["tags_secured"]) 55 )