本文整理汇总了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")