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


Python UserSocialAuth.get_social_auth_for_user方法代码示例

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


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

示例1: download_sheet_with_user

# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def download_sheet_with_user(user, filename="membership.csv"):
    """
    Download the membership with a user's credentials

    :type user: users.models.User
    :param user:
    :return: boolean of successful download
    """
    try:
        social = UserSocialAuth.get_social_auth_for_user(user).get()
    except UserSocialAuth.DoesNotExist:
        return False

    extra = social.extra_data
    expiry = datetime.utcnow() + timedelta(seconds=int(extra["expires"]))
    credentials = OAuth2Credentials(
        extra["access_token"],
        settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY,
        settings.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET,
        extra["refresh_token"],
        expiry,
        GOOGLE_TOKEN_URI,
        None,
        revoke_uri=GOOGLE_REVOKE_URI,
    )
    service = build_service_from_credentials(credentials)
    try:
        file = service.files().get(fileId=settings.GOOGLE_MEMBERSHIP_FILE_ID).execute()
    except googleapiclient.errors.HttpError:
        return False

    url = file["exportLinks"]["text/csv"]
    resp, content = service._http.request(url)
    open(filename, "wb").write(content)
    return True
开发者ID:HackUCF,项目名称:ppl,代码行数:37,代码来源:api.py

示例2: __init__

# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
    def __init__(self, user, request=None, provider='google-oauth2'):
        self.user = user
        self.request = request
        self.provider = provider

        self.strategy = load_strategy(request)
        self.user_social = UserSocialAuth.get_social_auth_for_user(user=self.user, provider=self.provider)[0]
        self.backend = self.user_social.get_backend_instance(strategy=self.strategy)
开发者ID:chwnam,项目名称:lifemotif,代码行数:10,代码来源:auth_dishes.py

示例3: profile_image_for_user

# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def profile_image_for_user(user):
    try:
        auth = UserSocialAuth.get_social_auth_for_user(user)[0]
        backend = auth.get_backend().name
        if backend == "google-oauth2":
            return HttpResponseRedirect(auth.extra_data["image"]["url"])
        elif backend == "facebook":
            return HttpResponseRedirect(fb_profile_image(auth.uid,50,50))
    except Exception, e:
        pass
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:12,代码来源:user_tools.py

示例4: get_large_user_image

# 需要导入模块: from social.apps.django_app.default.models import UserSocialAuth [as 别名]
# 或者: from social.apps.django_app.default.models.UserSocialAuth import get_social_auth_for_user [as 别名]
def get_large_user_image(user):
    try:
        auth = UserSocialAuth.get_social_auth_for_user(user)[0]
        backend = auth.get_backend().name
        if backend == "google-oauth2":
            url = auth.extra_data["image"]["url"]
            return HttpResponseRedirect("%s%i" % (url[:-2],200))
        elif backend == "facebook":
            return HttpResponseRedirect(fb_profile_image(auth.uid,200,200))
    except Exception, e:
        pass
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:13,代码来源:user_tools.py


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