예제 #1
0
def backends_data(user):
    """Return backends data for given user.

    Will return a dict with values:
        associated: UserSocialAuth model instances for currently
                    associated accounts
        not_associated: Not associated (yet) backend names.
        backends: All backend names.

    If user is not authenticated, then first list is empty, and there's no
    difference between the second and third lists.
    """
    available = BACKENDS.keys()
    values = {
        'associated': [],
        'not_associated': available,
        'backends': available
    }

    # user comes from request.user usually, on /admin/ it will be an instance
    # of auth.User and this code will fail if a custom User model was defined
    if isinstance(user, User) and user.is_authenticated():
        associated = user.social_auth.all()
        not_associated = list(
            set(available) - set(assoc.provider for assoc in associated))
        values['associated'] = associated
        values['not_associated'] = not_associated
    return values
def backends_data(user):
    """Return backends data for given user.

    Will return a dict with values:
        associated: UserSocialAuth model instances for currently
                    associated accounts
        not_associated: Not associated (yet) backend names.
        backends: All backend names.

    If user is not authenticated, then first list is empty, and there's no
    difference between the second and third lists.
    """
    available = BACKENDS.keys()
    values = {'associated': [],
              'not_associated': available,
              'backends': available}

    # user comes from request.user usually, on /admin/ it will be an instance
    # of auth.User and this code will fail if a custom User model was defined
    if isinstance(user, User) and user.is_authenticated():
        associated = user.social_auth.all()
        not_associated = list(set(available) -
                              set(assoc.provider for assoc in associated))
        values['associated'] = associated
        values['not_associated'] = not_associated
    return values
 def get_backends():
     keys = BACKENDS.keys()
     accounts = dict(zip(keys, [None] * len(keys)))
     
     if isinstance(request.user, User) and request.user.is_authenticated():
         for associated in request.user.social_auth.all():
             accounts[associated.provider.replace('-', '_')] = associated
     return accounts
예제 #4
0
def home(request):
	'''
		This function is used to generate the login page or
		redirect the already logged users to his dashboard
	'''
	if request.user.is_authenticated():
		return HttpResponseRedirect('dashboard')
	else:
		backends=[]
		for name, backend in BACKENDS.iteritems():
			if name == 'facebook':
				backends.append((name,backend))
				break
		return render_to_response('home.html',{'backends':backends},RequestContext(request))
예제 #5
0
def grouped_backends():
    """Group backends by type"""
    backends = {'oauth': [], 'oauth2': [], 'openid': []}

    for name, backend in BACKENDS.iteritems():
        if issubclass(backend, BaseOAuth2):
            key = 'oauth2'
        elif issubclass(backend, BaseOAuth):
            key = 'oauth'
        elif issubclass(backend, OpenIdAuth):
            key = 'openid'
        else:
            print name, backend
        backends[key].append((name, backend))
    return backends
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.
    """
    keys = BACKENDS.keys()
    accounts = dict(zip(keys, [None] * len(keys)))
    
    if isinstance(request.user, User) and request.user.is_authenticated():
        for associated in request.user.social_auth.all():
            accounts[associated.provider.replace('-', '_')] = associated
    
    return {'social_auth': accounts}
예제 #7
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.
    """
    keys = BACKENDS.keys()
    accounts = dict(zip(keys, [None] * len(keys)))

    if isinstance(request.user, User) and request.user.is_authenticated():
        for associated in request.user.social_auth.all():
            accounts[associated.provider.replace('-', '_')] = associated

    return {'social_auth': accounts}
예제 #8
0
def grouped_backends():
    """Group backends by type"""
    backends = {'oauth': [],
                'oauth2': [],
                'openid': []}

    for name, backend in BACKENDS.iteritems():
        if issubclass(backend, BaseOAuth2):
            key = 'oauth2'
        elif issubclass(backend, BaseOAuth):
            key = 'oauth'
        elif issubclass(backend, OpenIdAuth):
            key = 'openid'
        else:
            print name, backend
        backends[key].append((name, backend))
    return backends
def backends_data(user):
    """Return backends data for given user.

    Will return a dict with values:
        associated: UserSocialAuth model instances for currently
                    associated accounts
        not_associated: Not associated (yet) backend names.
        backends: All backend names.

    If user is not authenticated, then first list is empty, and there's no
    difference between the second and third lists.
    """
    available = BACKENDS.keys()
    values = {'associated': [],
              'not_associated': available,
              'backends': available}

    if user.is_authenticated():
        associated = user.social_auth.all()
        not_associated = list(set(available) -
                              set(assoc.provider for assoc in associated))
        values['associated'] = associated
        values['not_associated'] = not_associated
    return values