Ejemplo n.º 1
0
 def disconnect(self, user, association_id=None):
     """Deletes current backend from user if associated.
     Override if extra operations are needed.
     """
     if association_id:
         UserSocialAuth.get_social_auth_for_user(user)\
                         .get(id=association_id).delete()
     else:
         UserSocialAuth.get_social_auth_for_user(user)\
                         .filter(provider=self.AUTH_BACKEND.name).delete()
Ejemplo n.º 2
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 = get_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 hasattr(user, 'is_authenticated') and user.is_authenticated():
        associated = UserSocialAuth.get_social_auth_for_user(user)
        not_associated = list(
            set(available) - set(assoc.provider for assoc in associated))
        values['associated'] = associated
        values['not_associated'] = not_associated
    return values
Ejemplo n.º 3
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 = get_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 hasattr(user, 'is_authenticated') and user.is_authenticated():
        associated = UserSocialAuth.get_social_auth_for_user(user)
        not_associated = list(set(available) -
                              set(assoc.provider for assoc in associated))
        values['associated'] = associated
        values['not_associated'] = not_associated
    return values
Ejemplo n.º 4
0
 def context_value():
     keys = get_backends().keys()
     accounts = dict(zip(keys, [None] * len(keys)))
     user = request.user
     if hasattr(user, 'is_authenticated') and user.is_authenticated():
         accounts.update((assoc.provider.replace('-', '_'), assoc)
                 for assoc in UserSocialAuth.get_social_auth_for_user(user))
     return accounts
Ejemplo n.º 5
0
 def context_value():
     keys = get_backends().keys()
     accounts = dict(zip(keys, [None] * len(keys)))
     user = request.user
     if hasattr(user, 'is_authenticated') and user.is_authenticated():
         accounts.update(
             (assoc.provider.replace('-', '_'), assoc)
             for assoc in UserSocialAuth.get_social_auth_for_user(user))
     return accounts