def get_user_from_cas_resp(cas_resp):
 if cas_resp.user:
  user = User.objects.filter(guids___id=cas_resp.user).first()
  if user:
   return (user, None, 'authenticate')
  else:
   external_credential = validate_external_credential(cas_resp.user)
   if (not external_credential):
    return (None, None, None)
   user = get_user(external_id_provider=external_credential['provider'], external_id=external_credential['id'])
   if user:
    return (user, external_credential, 'authenticate')
   else:
    return (None, external_credential, 'external_first_login')

def get_user_from_cas_resp ( cas_resp ) : if cas_resp . user : user = User . objects . filter ( guids___id = cas_resp . user ) . first ( ) if user : return ( user , None , 'authenticate' ) else : external_credential = validate_external_credential ( cas_resp . user ) if ( not external_credential ) : return ( None , None , None ) user = get_user ( external_id_provider = external_credential [ 'provider' ] , external_id = external_credential [ 'id' ] ) if user : return ( user , external_credential , 'authenticate' ) else : return ( None , external_credential , 'external_first_login' )
given a cas service validation response .