mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-19 23:46:53 +00:00
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m27s
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
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
|