def wrapper(request, *args, **kwargs): # if this is already the callback, do not wrap. if getattr(request, 'avoid_redirect', False): logger.debug('entered calback. View: %s, kwargs: %s' % (view, kwargs)) return view(request, *args, **kwargs) if 'facebook' in request.META['HTTP_USER_AGENT']: return view(request, *args, **kwargs) session = get_session(request) app_dict = get_app_dict(app_name) signed_request = session.signed_request if not signed_request: #logger.debug('No signed_request in current session. Returning View.') #return view(request, *args, **kwargs) logger.debug( 'No signed_request in current session. Redirecting.\n') url = u'%s?sk=app_%s&app_data=%s' % (app_dict['REDIRECT-URL'], app_dict['ID'], urlencode(request.path)) return render_to_response('facebook/redirecter.html', {'destination': url}, RequestContext(request)) logger.debug('signed_request: %s\n' % signed_request) # This is handled by the Redirect2AppDataMiddleware if 'app_data' in signed_request: app_data = signed_request['app_data'] del request.session['facebook']['signed_request']['app_data'] request.session.modified = True logger.debug('found app_data url: %s' % app_data) return HttpResponseRedirect(app_data) else: #check if the app is inside the specified page. try: page = signed_request['page']['id'] except KeyError: page = 0 if int(page) not in app_dict['PAGES'] and getattr( settings, 'FB_REDIRECT', True): url = u'%s?sk=app_%s&app_data=%s' % ( app_dict['REDIRECT-URL'], app_dict['ID'], urlencode(request.path)) logger.debug( 'Tab is not in original Page (id: %s, should be: %s. Redirecting to: %s' % (page, app_dict['PAGES'][0], url)) return render_to_response('facebook/redirecter.html', {'destination': url}, RequestContext(request)) return view(request, *args, **kwargs)
def render(self, request, context, **kwargs): session = get_session(request) signed_request = session.signed_request context = {'content': self} context.update(self.social_context.get_context(request=request, signed_request=signed_request)) if getattr(self, 'dimension', False): context.update({'dimensions' : self.dimension.split('x')}) template = 'content/facebook/%s.html' % self.type return render_to_string(template.lower() , context)
def channel(request): """ Returns the channel.html file as described in http://developers.facebook.com/docs/reference/javascript/FB.init/""" fb = get_session(request) try: locale = fb.signed_request['user']['locale'] except (AttributeError, KeyError, TypeError): # TODO really catch AttributeError too? locale = 'en_US' #TODO: Make this nicer. t=datetime.now()+timedelta(weeks=500) response = HttpResponse(loader.render_to_string('facebook/channel.html', {'locale': locale}, context_instance=RequestContext(request))) response['Expires'] = t.ctime() return response
def wrapper(request, *args, **kwargs): # if this is already the callback, do not wrap. if getattr(request, "avoid_redirect", False): logger.debug("entered calback. View: %s, kwargs: %s" % (view, kwargs)) return view(request, *args, **kwargs) if "facebook" in request.META["HTTP_USER_AGENT"]: return view(request, *args, **kwargs) session = get_session(request) app_dict = get_app_dict(app_name) signed_request = session.signed_request if not signed_request: # logger.debug('No signed_request in current session. Returning View.') # return view(request, *args, **kwargs) logger.debug("No signed_request in current session. Redirecting.\n") url = u"%s?sk=app_%s&app_data=%s" % (app_dict["REDIRECT-URL"], app_dict["ID"], urlencode(request.path)) return render_to_response("facebook/redirecter.html", {"destination": url}, RequestContext(request)) logger.debug("signed_request: %s\n" % signed_request) # This is handled by the Redirect2AppDataMiddleware if "app_data" in signed_request: app_data = signed_request["app_data"] del request.session["facebook"]["signed_request"]["app_data"] request.session.modified = True logger.debug("found app_data url: %s" % app_data) return HttpResponseRedirect(app_data) else: # check if the app is inside the specified page. try: page = signed_request["page"]["id"] except KeyError: page = 0 if int(page) not in app_dict["PAGES"] and getattr(settings, "FB_REDIRECT", True): url = u"%s?sk=app_%s&app_data=%s" % ( app_dict["REDIRECT-URL"], app_dict["ID"], urlencode(request.path), ) logger.debug( "Tab is not in original Page (id: %s, should be: %s. Redirecting to: %s" % (page, app_dict["PAGES"][0], url) ) return render_to_response("facebook/redirecter.html", {"destination": url}, RequestContext(request)) return view(request, *args, **kwargs)
def channel(request): """ Returns the channel.html file as described in http://developers.facebook.com/docs/reference/javascript/FB.init/""" fb = get_session(request) try: locale = fb.signed_request['user']['locale'] except (AttributeError, KeyError, TypeError): # TODO really catch AttributeError too? locale = 'en_US' #TODO: Make this nicer. t = datetime.now() + timedelta(weeks=500) response = HttpResponse( loader.render_to_string('facebook/channel.html', {'locale': locale}, context_instance=RequestContext(request))) response['Expires'] = t.ctime() return response
def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME): fb_app=get_app_dict() # TODO: Make this multi-app capable. Add app to login-url. fb_session = get_session(request) fb_session.store_token(None) response = auth_views.logout(request, next_page, template_name, redirect_field_name) # This might lead to unexpected results with multiple apps. response.delete_cookie("fbsr_" + fb_app['ID']) redirect_to = next_page or request.REQUEST.get(redirect_field_name, '') if not redirect_to or ' ' in redirect_to: redirect_to = fb_app['REDIRECT-URL'] return redirect(redirect_to)
def logout(request, next_page=None, template_name='registration/logged_out.html', redirect_field_name=REDIRECT_FIELD_NAME): fb_app = get_app_dict( ) # TODO: Make this multi-app capable. Add app to login-url. fb_session = get_session(request) fb_session.store_token(None) response = auth_views.logout(request, next_page, template_name, redirect_field_name) # This might lead to unexpected results with multiple apps. response.delete_cookie("fbsr_" + fb_app['ID']) redirect_to = next_page or request.REQUEST.get(redirect_field_name, '') if not redirect_to or ' ' in redirect_to: redirect_to = fb_app['REDIRECT-URL'] return redirect(redirect_to)