def social_user(strategy, uid, user=None, *args, **kwargs):
    provider = strategy.backend.name
    social = strategy.storage.user.get_social_auth(provider, uid)
    if social:
        if user and social.user != user:
            msg = 'This %s account is already in use.' % provider
            raise AuthAlreadyAssociated(strategy.backend, msg)
        elif not user:
            user = social.user
    return {'social': social, 'user': user, 'new_association': False}
Beispiel #2
0
def verify_username(strategy, backend, details, user=None, **kwargs):
    """Verified whether username is still free.

    It can happen that user has registered several times or other user has
    taken the username meanwhile.
    """
    if not user and 'username' in details:
        if User.objects.filter(username__iexact=details['username']).exists():
            raise AuthAlreadyAssociated(
                backend,
                _('This username is already taken. Please choose another.'))
Beispiel #3
0
def new_associate_user(strategy, uid, user, extra_data=None):
    if UserSocialAuth.objects.filter(user=user,
                                     provider=strategy.backend.name).exists():
        raise AuthAlreadyAssociated(strategy.backend)
    if not extra_data:
        extra_data = {}
    result = associate_user(strategy, uid, user=user)
    sc_user = result['social']
    if sc_user:
        sc_user.extra_data = extra_data
        sc_user.save()
    return sc_user
Beispiel #4
0
def social_user(backend, uid, user=None, *args, **kwargs):
    provider = backend.name
    social = backend.strategy.storage.user.get_social_auth(provider, uid, user__subdomain=kwargs.get('subdomain'))
    if social:
        if user and social.user != user:
            msg = 'This {0} account is already in use.'.format(provider)
            raise AuthAlreadyAssociated(backend, msg)
        elif not user:
            user = social.user
    return {'social': social,
            'user': user,
            'is_new': user is None,
            'new_association': social is None}
Beispiel #5
0
def selective_social_user(backend, uid, user=None, *args, **kwargs):
    provider = backend.name
    social = backend.strategy.storage.user.get_social_auth(provider, uid)
    if social:
        if user and social.user != user:
            if backend.name not in ('twitter', 'facebook'):
                msg = 'This {0} account is already in use.'.format(provider)
                raise AuthAlreadyAssociated(backend, msg)
        elif not user:
            user = social.user
    return {'social': social,
            'user': user,
            'is_new': user is None,
            'new_association': False}
def new_associate_user(strategy, uid, user, extra_data=None, created_on='web'):
    provider = strategy.backend.name
    if UserSocialAuth.objects.filter(user=user, provider=provider).exists():
        raise AuthAlreadyAssociated(strategy.backend)
    if not extra_data:
        extra_data = {}
    result = associate_user(strategy, uid, user=user)
    sc_user = result['social']
    if sc_user:
        sc_user.extra_data = extra_data
        sc_user.created_on = created_on
        if provider == 'weixin':
            sc_user.weixin_unionid = extra_data['unionid']
        sc_user.save()
    return sc_user
Beispiel #7
0
def social_user(backend, uid, user=None, *args, **kwargs):
    """
    Search for UserSocialAuth.
    """
    provider = backend.name
    social = backend.strategy.storage.user.get_social_auth(provider, uid)
    if social:
        if user and social.user != user and not user.groups.filter(
                name='Temporary').exists():
            if not_allowed_to_merge(user, social.user):
                msg = 'Merge aborted due to providers intersection.'
                raise AuthAlreadyAssociated(backend, msg)
        elif not user or user.groups.filter(name='Temporary').exists():
            user = social.user
    return {
        'social': social,
        'user': user,
        'is_new': user is None,
        'new_association': False
    }
Beispiel #8
0
class AuthAlreadyAssociatedTest(BaseExceptionTestCase):
    exception = AuthAlreadyAssociated('foobar')
    expected_message = ''