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


Python Profile.facebook方法代码示例

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


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

示例1: attach_fb

# 需要导入模块: from users.models import Profile [as 别名]
# 或者: from users.models.Profile import facebook [as 别名]
def attach_fb(request):
    if request.method == "POST":
        data = request.POST
        facebookid = data["id"]
        email = data["email"]
        first_name = data["first_name"]
        last_name = data["last_name"]

        user, profile = None, None
        u_email = None
        try:
            u_email = UserEmail.objects.get(email=email)
            profile = u_email.user
            user = profile.user
        except UserEmail.DoesNotExist:
            try:
                user = User.objects.get(Q(email=email) | Q(username=email))
            except User.DoesNotExist:
                user = User.objects.create_user(email, email, None)
                user.first_name = first_name
                user.last_name = last_name
                user.save()
        if not user.first_name:
            user.first_name = first_name
            user.save()
        if not user.last_name:
            user.last_name = last_name
            user.save()

        try:
            profile = Profile.objects.get(user=user)
        except Profile.DoesNotExist:
            profile = Profile(user=user, full_name="%s %s" % (first_name, last_name))
        # if not profile.full_name: overwrite facebook name
        profile.full_name = "%s %s" % (first_name, last_name)
        profile.facebook = facebookid
        profile.save()
        if not u_email:
            u_email = UserEmail(email=email, user=profile, type="subscription")
            u_email.save()
        if request.user:
            auth.logout(request)
            request.session.flush()
        user = auth.authenticate(facebook_user=user, **dict(request=request))
        request.session["logged_through_facebook"] = True
        if user:
            request.session["atg_username"] = user.username
            set_logged_in_user(request, user)
            log.info("FACEBOOK USER LOGGED IN: %s" % user)
            return HttpResponse("OK")
    else:
        return HttpResponse("OK")
    return HttpResponse("FAILED")
开发者ID:,项目名称:,代码行数:55,代码来源:


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