'Returns a correctly sorted list of all interfaces the user
has enabled.  If `return_missing` is set to `True` then all
interfaces are returned even if not enabled.'

def all_interfaces_for_user(self, user, return_missing=False):

    def _sort(x):
        return sorted(x, key=(lambda x: ((x.type == 0), x.type)))
    ifaces = [x.interface for x in Authenticator.objects.filter(user=user, type__in=[a.type for a in available_authenticators()])]
    if return_missing:
        rvm = dict(AUTHENTICATOR_INTERFACES)
        for iface in ifaces:
            rvm.pop(iface.interface_id, None)
        for iface_cls in six.itervalues(rvm):
            if iface_cls.is_available:
                ifaces.append(iface_cls())
    return _sort(ifaces)
