def user_has_valid_totp_device(user):
    """Determine if the user has a valid TOTP device.

    Parameters
    ----------
    user
        The current Django user object.

    Returns
    -------
    boolean
        ``True`` if ``user`` has a valid TOTP device, ``False``
        otherwise.
    """
    if not user.is_authenticated:
        return False

    return user.totpdevice_set.filter(confirmed=True).exists()