mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-19 23:46:53 +00:00
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m15s
58 lines
1.9 KiB
Python
58 lines
1.9 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()
|
|
api_nic = data.get("nic")
|
|
api_name = data.get("name_en")
|
|
api_house_name = data.get("house_name_en")
|
|
api_dob = data.get("dob")
|
|
print(f"API nic: {api_nic}")
|
|
print(f"API name: {api_name}")
|
|
print(f"API house name: {api_house_name}")
|
|
print(f"API dob: {api_dob}")
|
|
|
|
user_nic = user.id_card
|
|
user_name = f"{user.first_name} {user.last_name}"
|
|
user_house_name = user.address
|
|
user_dob = user.dob.isoformat()
|
|
|
|
print(f"User nic: {user_nic}")
|
|
print(f"User name: {user_name}")
|
|
print(f"User house name: {user_house_name}")
|
|
print(f"User dob: {user_dob}")
|
|
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").split("T")[0] == 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
|