Example #1
0
def link_fb_user(request, user, fbprofile):
    if not hasattr(user, "fb_set"):
        if user.is_active:
            login(request, user)
            # TODO: set callback to perform other user activation
            try:
                user_old = User.objects.get(id=fbprofile["id"])
                fbuser = FBUser.objects.get(user=user_old)
                for item in user_old.item_set:
                    item.owner = user
                    item.save()
                fbuser.user = user
                fbuser.save()
                # TODO: delete user_old
            except:
                fbuser = FBUser(
                    user=user,
                    uid=fbprofile["id"],
                    name=fbprofile["name"],
                    profile_url=fbprofile["link"],
                    access_token=request.session["fbuser"]["access_token"],
                )
                fbuser.save()
            user = fbuser.authenticate()
            login(request, user)
            # Redirect to a success page.
            facebook_link.send(sender=self, fbuser=fbuser, user=user)
            return HttpResponseRedirect(get_next(request)), user, ""
        else:
            # Return a 'disabled account' error message
            pass
    else:
        message = "This account already has a Facebook account associated with it."
        return None, None, ""
Example #2
0
def fbreg(request, show_form=True):
    next = get_next(request)
    fbprofile = request.session.get("fbprofile", None)
    fbgraph = request.session.get("fbgraph", None)
    if not (fbprofile and fbgraph):
        return HttpResponseRedirect("/")
    next = request.GET.get("next", None)
    if request.method == "POST" or show_form == False:
        user = User.objects.create_user(request.fbprofile["id"], "", password=None)
        user.first_name = fbprofile["first_name"]
        user.last_name = fbprofile["last_name"]
        user.email = fbprofile["email"]
        user.is_active = True
        user.set_unusable_password()
        user.save()
        fbuser = FBUser(
            user=user,
            uid=fbprofile["id"],
            name=fbprofile["name"],
            profile_url=fbprofile["link"],
            access_token=request.session["fbuser"]["access_token"],
        )
        fbuser.save()
        user = fbuser.authenticate()
        login(request, user)
        facebook_new_account.send(sender=self, fbuser=fbuser, user=user)
        return HttpResponseRedirect(next)
    return render_to_response(
        "fbuser/signup.djhtml",
        {"path": request.path, "form": None, "next": next, "show_terms": True, "show_fblink": True},
        context_instance=RequestContext(request),
    )