示例#1
0
def create_new_accounts(username, selected_provider=None):
    user = AtmosphereUser.objects.get(username=username)
    if not user.is_valid():
        raise InvalidUser("The account %s is not yet valid." % username)

    providers = get_available_providers()
    identities = []
    if not providers:
        logger.error("No currently active providers")
        return identities
    if selected_provider and selected_provider not in providers:
        logger.error("The provider %s is NOT in the list of currently active providers. Account will not be created" % selected_provider)
        return identities
    for provider in providers:
        new_identity = create_new_account_for(provider, user)
        if new_identity:
            identities.append(new_identity)
    return identities
示例#2
0
def _get_providers(username, selected_provider=None):
    from core.models import Provider
    user = AtmosphereUser.objects.get(username=username)
    if not user.is_valid():
        raise InvalidUser("The account %s is not yet valid." % username)

    public_providers = Provider.objects.filter(only_current(),
                                               active=True,
                                               public=True)

    providers = user.current_providers.filter(only_current(), active=True)
    if not providers:
        providers = public_providers
    else:
        providers |= public_providers
    if selected_provider and providers and selected_provider not in providers:
        logger.error(
            "The provider %s is NOT in the list of currently active providers. Account will not be created"
            % selected_provider)
        return (user, providers.none())

    return (user, providers)