code: def get_username(identifier):
      
      pattern = re.compile('.+@\w+\..+')
      if pattern.match(identifier):
          try:
              user = User.objects.get(email=identifier)
          except:
              raise Http404
          else:
              return user.username
      else:
          return identifier
docs: Checks if a string is a email adress or not.