@@ -429,16 +429,19 @@ def directauth(request):
429429 data = None
430430
431431 if raw_data is None or data is None :
432+ log .log ("Request body is either missing or invalid" )
432433 return HttpResponse (json .dumps (dict (result = "failure" ,reason = "invalid post" )), content_type = 'application/json' )
433434
434435 authtoken = data .get ('authtoken' , None )
435436 username = data .get ('username' , None )
436437 password = data .get ('password' , None )
437438
438439 if any ([item is None for item in (authtoken , username , password )]):
440+ log .log ("One or more mandatory fields are missing: authtoken, username, password" )
439441 return HttpResponse (json .dumps (dict (result = "failure" ,reason = "invalid post" )), content_type = 'application/json' )
440442
441443 if not is_valid_token ("ietf.api.views.directauth" , authtoken ):
444+ log .log ("Auth token provided is invalid" )
442445 return HttpResponse (json .dumps (dict (result = "failure" ,reason = "invalid authtoken" )), content_type = 'application/json' )
443446
444447 user_query = User .objects .filter (username__iexact = username )
@@ -449,18 +452,20 @@ def directauth(request):
449452
450453
451454 # Note well that we are using user.username, not what was passed to the API.
452- if user_query .count () == 1 and authenticate (username = user_query .first ().username , password = password ):
455+ user_count = user_query .count ()
456+ if user_count == 1 and authenticate (username = user_query .first ().username , password = password ):
453457 user = user_query .get ()
454458 if user_query .filter (person__isnull = True ).count () == 1 : # Can't inspect user.person direclty here
455- log .log (f"Direct auth of personless user { user .pk } :{ user .username } " )
459+ log .log (f"Direct auth success ( personless user): { user .pk } :{ user .username } " )
456460 else :
457- log .log (f"Direct auth: { user .pk } :{ user .person .plain_name ()} " )
461+ log .log (f"Direct auth success : { user .pk } :{ user .person .plain_name ()} " )
458462 return HttpResponse (json .dumps (dict (result = "success" )), content_type = 'application/json' )
459463
460- log .log (f"Direct auth failure: { username } " )
464+ log .log (f"Direct auth failure: { username } ( { user_count } user(s) found) " )
461465 return HttpResponse (json .dumps (dict (result = "failure" , reason = "authentication failed" )), content_type = 'application/json' )
462466
463467 else :
468+ log .log (f"Request must be POST: { request .method } received" )
464469 return HttpResponse (status = 405 )
465470
466471
0 commit comments