def social_page_select(request, site): # Social site page selection endpoint social_center = SocialCenter() if not social_center.has_site(site): return HttpResponseNotFound("Site not found") if not social_center.must_select_page(site): return HttpResponseServerError("Site does not support pages.") main_token_key = "%s_main_token" % site main_token = request.session[main_token_key] del request.session[main_token_key] page_id = request.POST["pageId"] social_center = SocialCenter() result = social_center.authenticate(site, main_token, page_id) logger.debug(result) if "main_token" in result: return HttpResponse("OK") else: return HttpResponseServerError("Could not obtain page token.")
def social_callback(request, site): # Social site callback view # Retrieves the tokens from the authentication response. social_center = SocialCenter() if not social_center.has_site(site): return HttpResponseNotFound("Site not found") if "error" in request.GET: return HttpResponseServerError("ERROR: " + request.GET["error"]) auth_data_key = "%s_auth_data" % site main_token_key = "%s_main_token" % site client_token_name = social_center.get_client_token_name(site) auth_data = request.session[auth_data_key] client_token = request.GET[client_token_name] del request.session[auth_data_key] result = social_center.process_client_token(site, client_token, auth_data) logger.debug(result) if "main_token" not in result: return HttpResponseServerError("Could not retrieve token") main_token = result["main_token"] if social_center.must_select_page(site): pages = social_center.get_pages(site, main_token) request.session[main_token_key] = main_token return render(request, "socialnetwork-select-page.html", { "pages" : pages, "root_uri" : reverse("socialnetwork.views.social"), "process_uri" : reverse("socialnetwork.views.social_page_select", kwargs={ "site" : site }) }) else: social_center.authenticate(site, main_token, result.get("sub_token", None)) return redirect("socialnetwork.views.social")