mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-27 22:03:58 +00:00
registration and verify abuse WIP
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m27s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m27s
This commit is contained in:
41
api/tasks.py
Normal file
41
api/tasks.py
Normal file
@ -0,0 +1,41 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
from api.models import User
|
||||
import requests
|
||||
from apibase.env import env, BASE_DIR
|
||||
import os
|
||||
|
||||
PERSON_API_URL = env.str("PERSON_VERIFY_BASE_URL", "")
|
||||
|
||||
env.read_env(os.path.join(BASE_DIR, ".env"))
|
||||
|
||||
|
||||
def verify_user_with_person_api_task(user_id: int):
|
||||
"""
|
||||
Verify the user with the Person API.
|
||||
:param user_id: The ID of the user to verify.
|
||||
"""
|
||||
|
||||
user = get_object_or_404(User, id=user_id)
|
||||
# Call the Person API to verify the user
|
||||
response = requests.get(f"{PERSON_API_URL}/api/person/{user.id_card}")
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print(f"Data from Person API: {data}")
|
||||
print("Data from of user: ", user.__dict__)
|
||||
if (
|
||||
data.get("nic") == user.id_card
|
||||
and data.get("name_en") == f"{user.first_name} {user.last_name}"
|
||||
and data.get("house_name_en") == user.address
|
||||
and data.get("dob") == user.dob.isoformat()
|
||||
):
|
||||
user.verified = True
|
||||
user.save()
|
||||
return True
|
||||
else:
|
||||
user.verified = False
|
||||
user.save()
|
||||
return False
|
||||
else:
|
||||
# Handle the error case
|
||||
print(f"Error verifying user: {response.status_code} - {response.text}")
|
||||
return False
|
Reference in New Issue
Block a user