当前位置: 首页>>代码示例>>Python>>正文


Python UserSocialAuth.get_social_auth方法代码示例

本文整理汇总了Python中social_auth.models.UserSocialAuth.get_social_auth方法的典型用法代码示例。如果您正苦于以下问题:Python UserSocialAuth.get_social_auth方法的具体用法?Python UserSocialAuth.get_social_auth怎么用?Python UserSocialAuth.get_social_auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在social_auth.models.UserSocialAuth的用法示例。


在下文中一共展示了UserSocialAuth.get_social_auth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
    def run(self, user_pk, provider):
        print "Running Friend import Tasks"
        user = User.objects.get(pk=user_pk) # get song santhe regestered user
        print "For",
        print user
        social = Provider(user, provider)   # get a reference to that persons social account (fb/twitter/google)
        total = 0
        
        for friend in social.friends():
            #getting his friends who use songsanthe
            social_auth = UserSocialAuth.get_social_auth(
                provider=provider,
                uid=friend["id"]
            )   
            if social_auth is not None:
                Suggestion.objects.create_suggestions(user, social_auth.user)
            total += 1

        #stupid suggestions generater

        strangers = User.objects.exclude(pk=user_pk)
        for stranger in strangers:
            print "The users and the strangers per iterations "
            print user,stranger
            suggested =  Suggestion.objects.create_suggestions(user,stranger)
            total +=1
        return total
开发者ID:NavaneethBhat,项目名称:SongSanthe,代码行数:29,代码来源:tasks.py

示例2: load_extra_data

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def load_extra_data(backend, details, response, uid, user, social_user=None,
                    *args, **kwargs):
    """Load extra data from provider and store it on current UserSocialAuth
    extra_data field.
    """
    social_user = social_user or \
                  UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        extra_data = backend.extra_data(user, uid, response, details)
        extra_data_field_name = "{0}_extra_data".format(backend.name)
        social_user_extra_data = getattr(social_user, extra_data_field_name)
        if extra_data and social_user_extra_data != extra_data:
            if social_user_extra_data:
                social_user_extra_data.update(extra_data)
            else:
                social_user_extra_data = extra_data

            #Getting the access token
            access_token_field_name = "{0}_access_token".format(backend.name)
            setattr(social_user, access_token_field_name, extra_data['access_token'])

            #Storing extra data
            social_user_extra_data.pop('access_token', None)
            social_user_extra_data.pop('id', None)
            setattr(social_user, extra_data_field_name, social_user_extra_data)

            social_user.save()
        return {'social_user': social_user}
开发者ID:kamotos,项目名称:django-social-auth,代码行数:30,代码来源:social.py

示例3: load_extra_data

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def load_extra_data(backend, details, response, uid, user, social_user=None,
                    *args, **kwargs):
    """Load extra data from provider and store it on current UserSocialAuth
    extra_data field.
    """
    social_user = social_user or \
                  UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        extra_data = backend.extra_data(user, uid, response, details)
        if kwargs.get('original_email') and not 'email' in extra_data:
            extra_data['email'] = kwargs.get('original_email')
        t_delta = extra_data.get('expires_in')
        if isinstance(t_delta, int):
            _time = datetime.datetime.now() + datetime.timedelta(seconds=t_delta)
            extra_data['expires_in'] = datetime.datetime(
                _time.year, _time.month, _time.day,
                _time.hour, _time.minute, _time.second)

        if extra_data and social_user.extra_data != extra_data:
            if social_user.extra_data:
                social_user.extra_data.update(extra_data)
            else:
                social_user.extra_data = extra_data
            social_user.save()
        return {'social_user': social_user}
开发者ID:amyangfei,项目名称:django-social-auth,代码行数:27,代码来源:social.py

示例4: social_auth_user

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def social_auth_user(backend, uid, user, *args, **kwargs):
    """
    Return UserSocialAuth details.
    """
    social_user = UserSocialAuth.get_social_auth(backend.name, uid, user)
    return {
        'social_user': social_user,
        'user': user,
        'new_association': False
    }
开发者ID:Kayle009,项目名称:sentry,代码行数:12,代码来源:social.py

示例5: social_auth_user

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def social_auth_user(backend, uid, user=None, *args, **kwargs):
    """Return UserSocialAuth account for backend/uid pair or None if it
    doesn't exists.

    Merge accounts if its another login from the same user.
    
    """
    request = kwargs["request"]
    session_user = request.user
    
    social_user = UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        if session_user.id and social_user.user.id != session_user.id:
            change_user(social_user.user, session_user)
            social_user = UserSocialAuth.get_social_auth(backend.name, uid)
            
    return {'social_user': social_user,
            'user': social_user.user,
            'new_association': False}
开发者ID:wikilife-org,项目名称:datadonor,代码行数:21,代码来源:social.py

示例6: run

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
 def run(self, user_pk, provider):
     user = User.objects.get(pk=user_pk)
     social = Provider(user, provider)
     total = 0
     for friend in social.friends():
         social_auth = UserSocialAuth.get_social_auth(
             provider=provider,
             uid=friend["id"]
         )
         if social_auth is not None:
             Suggestion.objects.create_suggestions(user, social_auth.user)
         total += 1
     return total
开发者ID:DvTooChgW,项目名称:socialbee,代码行数:15,代码来源:tasks.py

示例7: get_by_auth_id

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
    def get_by_auth_id(cls, auth_str):
        """
        Return the user identified by the auth id.

        Example::

            user = User.get_by_auth_id('twitter:julython')
        """
        provider, uid = auth_str.split(':')
        sa = UserSocialAuth.get_social_auth(provider, uid)
        if sa is None:
            return None
        return sa.user
开发者ID:kkszysiu,项目名称:julython.org,代码行数:15,代码来源:models.py

示例8: social_auth_user

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def social_auth_user(backend, uid, user=None, *args, **kwargs):
    """Return UserSocialAuth account for backend/uid pair or None if it
    doesn't exists.

    Raise AuthAlreadyAssociated if UserSocialAuth entry belongs to another user.
    """
    social_user = UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        if user and social_user.user != user:
            msg = ugettext('This %(provider)s account already in use.')
            raise AuthAlreadyAssociated(backend, msg % {'provider': backend.name})
        elif not user:
            user = social_user.user
    return {'social_user': social_user, 'user': user}
开发者ID:lihan,项目名称:django-social-auth,代码行数:16,代码来源:social.py

示例9: load_extra_data

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def load_extra_data(backend, details, response, uid, user, social_user=None, *args, **kwargs):
    """Load extra data from provider and store it on current UserSocialAuth
    extra_data field.
    """
    social_user = social_user or UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        extra_data = backend.extra_data(user, uid, response, details)
        if extra_data and social_user.extra_data != extra_data:
            if social_user.extra_data:
                social_user.extra_data.update(extra_data)
            else:
                social_user.extra_data = extra_data
            social_user.save()
            update_user_skill(social_user)
        return {"social_user": social_user}
开发者ID:sivaa,项目名称:eventsin,代码行数:17,代码来源:custom.py

示例10: social_auth_user

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def social_auth_user(backend, uid, user=None, *args, **kwargs):
    """Return UserSocialAuth account for backend/uid pair or None if it
    doesn't exists.

    Raise AuthAlreadyAssociated if UserSocialAuth entry belongs to another
    user.
    """
    social_user = UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        if user and social_user.user != user:
            merge_users(user, social_user.user, commit=True)
        elif not user:
            user = social_user.user
    return {'social_user': social_user,
            'user': user,
            'new_association': False}
开发者ID:ChimeraCoder,项目名称:GOctober,代码行数:18,代码来源:social.py

示例11: load_extra_data

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def load_extra_data(backend, details, response, uid, user, social_user=None,
                    *args, **kwargs):
    """Load extra data from provider and store it on current UserSocialAuth
    extra_data field.
    """
    social_user = social_user or \
                  UserSocialAuth.get_social_auth(backend.name, uid)

    if kwargs['is_new'] and EMAIL_CONFIRMATION:
        from ..models import EmailAddress
        emailaddress = EmailAddress(**{
            'user': user,
            'email': user.email,
            'verified': True,
            'primary': True
        })
        emailaddress.save()

    if social_user:
        extra_data = backend.extra_data(user, uid, response, details)
        if kwargs.get('original_email') and 'email' not in extra_data:
            extra_data['email'] = kwargs.get('original_email')
        if extra_data and social_user.extra_data != extra_data:
            if social_user.extra_data:
                social_user.extra_data.update(extra_data)
            else:
                social_user.extra_data = extra_data
            social_user.save()

        if backend.name == 'facebook' and kwargs['is_new']:
            response = json.loads(requests.get('https://graph.facebook.com/%s?access_token=%s' % (extra_data['id'], extra_data['access_token'])).content)

            try:
                user.city, user.country = response.get('hometown').get('name').split(', ')
            except AttributeError:
                pass

            try:
                user.birth_date = datetime.strptime(response.get('birthday'), '%m/%d/%Y').date()
            except AttributeError:
                pass

            user.save()

        return {'social_user': social_user}
开发者ID:beratx,项目名称:nodeshot,代码行数:47,代码来源:pipeline.py

示例12: load_extra_data

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def load_extra_data(backend, details, response, uid, user, social_user=None,
                    *args, **kwargs):
    """Load extra data from provider and store it on current UserSocialAuth
    extra_data field.
    """
    social_user = social_user or \
                  UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        extra_data = backend.extra_data(user, uid, response, details)
        if kwargs.get('original_email') and not 'email' in extra_data:
            extra_data['email'] = kwargs.get('original_email')
        if extra_data and social_user.extra_data != extra_data:
            if social_user.extra_data:
                social_user.extra_data.update(extra_data)
            else:
                social_user.extra_data = extra_data
            social_user.save()
        return {'social_user': social_user}
开发者ID:KrzysiekJ,项目名称:django-social-auth,代码行数:20,代码来源:social.py

示例13: do_facebook_registration

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def do_facebook_registration(data):
    print data
    uid = data["facebook"]["id"]
    #backend = get_backend("facebook")
    social_user = UserSocialAuth.get_social_auth("facebook", uid)
    
    if social_user:
        social_user.extra_data = data["facebook"]
        social_user.save()
    
    else:
        user = UserSocialAuth.create_user(username=get_username(), email="")
        Profile.objects.get_or_create(user=user)
        social_user = UserSocialAuth.objects.create(user=user, provider="facebook", uid=uid, extra_data=data["facebook"])
        
    dd_user_id = social_user.user.id
    facebook_service = SocialServiceLocator.get_instane().build_service_by_name("facebook")
    facebook_service.pull_user_info(dd_user_id, {"access_token": data["facebook"]["access_token"]})

    return dd_user_id 
开发者ID:wikilife-org,项目名称:datadonor,代码行数:22,代码来源:services.py

示例14: do_twitter_registration

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def do_twitter_registration(data):
    uid = data["twitter"]["id"]
    backend = get_backend("twitter")
    social_user = UserSocialAuth.get_social_auth(backend.name, uid)
    
    if social_user:
        social_user.extra_data = data["twitter"]
        social_user.save()
    
    else:
        
        user = UserSocialAuth.create_user(username=get_username(), email="")
        Profile.objects.create(user=user)
        social_user = UserSocialAuth.objects.create(user=user, provider="twitter", uid=uid, extra_data=data["twitter"])
        
    dd_user_id = social_user.user.id
    twitter_service = SocialServiceLocator.get_instane().build_service_by_name("twitter")
    twitter_service.pull_user_info(dd_user_id, {"access_token": data["twitter"]["access_token"], "twitter_id": uid})

    return dd_user_id 
开发者ID:wikilife-org,项目名称:datadonor,代码行数:22,代码来源:services.py

示例15: load_extra_data

# 需要导入模块: from social_auth.models import UserSocialAuth [as 别名]
# 或者: from social_auth.models.UserSocialAuth import get_social_auth [as 别名]
def load_extra_data(backend, details, response, uid, user, social_user=None,
                    *args, **kwargs):
    """Load extra data from provider and store it on current UserSocialAuth
    extra_data field.
    """
    
    # check if school has been filled out yet
    if user.get_profile().school == '':
        # check by email first
        if 'berkeley.edu' in response['email']:
            user.get_profile().school = 'Berkeley'
        elif 'dartmouth.edu' in response['email']:
            user.get_profile().school = 'Dartmouth'
        else:
            for index in range(0, len(response['education'])):
                # better to be too general than to filter by ID
                if 'Berkeley' in response['education'][index]['school']['name']: 
                    user.get_profile().school = 'Berkeley'
                    user.get_profile().save()
                    break
                elif 'Dartmouth' in response['education'][index]['school']['name']: 
                    user.get_profile().school = 'Dartmouth'
                    user.get_profile().save()
                    break

        user.get_profile().save()
        

    social_user = social_user or \
                  UserSocialAuth.get_social_auth(backend.name, uid)
    if social_user:
        extra_data = backend.extra_data(user, uid, response, details)
        if extra_data and social_user.extra_data != extra_data:
            if social_user.extra_data:
                social_user.extra_data.update(extra_data)
            else:
                social_user.extra_data = extra_data
            social_user.save()
        return {'social_user': social_user}
开发者ID:Maxpcf,项目名称:MyRepo,代码行数:41,代码来源:social.py


注:本文中的social_auth.models.UserSocialAuth.get_social_auth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。