def METHOD_NAME(request):
    try:
        data = json.loads(request.body)
    except json.JSONDecodeError:
        logger.debug("Login attempt without data")
        raise PermissionDenied("No data")
    name = data.get("username")
    password = data.get("password")
    try:
        user = authenticate(request, username=name, password=password)
        if user is not None:
            login(request, user)
            logger.info("Successful login: %s", name)
            return api_response(
                result=True, command="login", arguments=name, failed=False
            )
        else:
            logger.warning("Failed login attempt %s", name)
            raise PermissionDenied("Invalid login")
    except PermissionDenied:
        logger.warning("Failed login attempt %s", name)
        return api_response(command="login", arguments=name, status_code=401)