コード例 #1
0
def social_auth_backends(request):
    """Load Social Auth current user data to context.
    Will add a output from backends_data to context under social_auth key.
    """
    def context_value():
        return backends_data(request.user)

    return {'social_auth': LazyDict(context_value)}
コード例 #2
0
def social_auth_by_type_backends(request):
    """Load Social Auth current user data to context.
    Will add a output from backends_data to context under social_auth key where
    each entry will be grouped by backend type (openid, oauth, oauth2).
    """
    def context_value():
        data = backends_data(request.user)
        data['backends'] = group_backend_by_type(data['backends'])
        data['not_associated'] = group_backend_by_type(data['not_associated'])
        data['associated'] = group_backend_by_type(
            data['associated'], key=lambda assoc: assoc.provider)
        return data

    return {'social_auth': LazyDict(context_value)}
コード例 #3
0
def social_auth_by_name_backends(request):
    """Load Social Auth current user data to context.
    Will add a social_auth object whose attribute names are the names of each
    provider, e.g. social_auth.facebook would be the facebook association or
    None, depending on the logged in user's current associations. Providers
    with a hyphen have the hyphen replaced with an underscore, e.g.
    google-oauth2 becomes google_oauth2 when referenced in templates.
    """
    def context_value():
        keys = [key for key in list(get_backends().keys())]
        accounts = dict(list(zip(keys, [None] * len(keys))))
        user = request.user
        if hasattr(user, 'is_authenticated') and user.is_authenticated():
            accounts.update(
                (assoc.provider, assoc)
                for assoc in UserSocialAuth.get_social_auth_for_user(user))
        return accounts

    return {'social_auth': LazyDict(context_value)}