I just made a employee login and inside that for the eployee it includers the boolean for what can be acceswed by that employee now how will i make a code where it will be able to see that employee and be able to hide that p[art in the front if it false
@csrf_exempt
@api_view(['POST'])
def employee_login(request):
try:
data = json.loads(request.body) # Changed to json.loads(request.body)
print("Request Data:", data) # Print the request data for debugging
branch_name = data.get('branch_name')
username = data.get('username')
password = data.get('password')
if not branch_name:
return JsonResponse({'message': 'Branch name not provided'}, status=400)
if not username or not password:
return JsonResponse({'message': 'Username and password are required'}, status=400)
# Determine the database to use
db_name = f'branch_{branch_name.lower()}'
print(f"Database being used: {db_name}") # Print the database being used for debugging
if db_name not in settings.DATABASES:
print(f"Branch database not found: {db_name}") # Print if the branch database is not found
return JsonResponse({'message': 'Branch database not found'}, status=404)
# Fetch the employee user from the branch-specific database
try:
employee = Employee.objects.using(db_name).get(username=username)
print(f"Employee found: {employee.username}") # Print the found employee's username
except Employee.DoesNotExist:
print(f"User not found: {username}") # Print if the user is not found
return JsonResponse({'message': 'User not found'}, status=404)