def process_request(self, request): request.additional_context = {} if "admin" in request.path: return None if 'request_ids' in request.REQUEST: rids = request.REQUEST['request_ids'].split(",") request.session['request_ids'] = rids if request.session.get('FBAuth', False) or 'fb_' in request.path or 'code' in request.REQUEST: ## AUTORYZACJA FACEBOOKOWA ## token = request.session.get('oauth_token', False) if token and int(time.time()) < request.session.get('oauth_token_exp', 0): request.fb = api.GraphAPI(token, "https" if request.is_secure() else "http", APPID, APPURL) if not request.user.is_authenticated(): Profile.createFBAccountOrLogin(request) elif "code" not in request.REQUEST: csrf_state = uuid.uuid1() request.session['csrf_state'] = csrf_state url = "https://www.facebook.com/dialog/oauth?client_id=%(id)d&redirect_uri=%(url)s&state=%(csrf_state)s&scope=%(scope)s" inner_url = urllib.quote_plus(APPURL).strip() + "?" request.session['path'] = request.path request.session['path_info'] = request.path_info # redirect topmost frame to facebook auth dialog return render_to_response('facebook.html', { 'url': url % {'id':APPID, 'scope':APPSCOPE, 'url':inner_url, 'csrf_state':csrf_state }} ) #user comes back from oauth dialog elif "code" in request.REQUEST: #don't come in here again try: del request.session['csrf_state'] except: pass #refresh # user data is put into session, fb api is initialized inner_url = APPURL token = api.get_access_token_from_code(request.REQUEST['code'], inner_url, APPID, APPSECRET) request.session['oauth_token'] = token['access_token'] request.session['oauth_token_exp'] = int(time.time()) + int(token['expires']) request.fb = api.GraphAPI(request.session.get('oauth_token', False), "https" if request.is_secure() else "http", APPID, APPURL) if not request.user.is_authenticated(): Profile.createFBAccountOrLogin(request) return None else: token = request.session.get('oauth_token', False) if token and int(time.time()) < request.session.get('oauth_token_exp', 0): request.fb = api.GraphAPI(token, "https" if request.is_secure() else "http", APPID, APPURL) else: request.fb = None return None
def get_context_data(self, **kwargs): if'TranscriptionText' in self.request.REQUEST: note = Note.getForUser(Profile.getUserByPhone(self.request.REQUEST['From'][1:])).order_by('-id')[0] logger.error(self.request.REQUEST['TranscriptionText']) for user in User.objects.all(): if user.first_name + " " + user.last_name == self.request.REQUEST['TranscriptionText']: logger.error('match!') note.shares.add(user) return {'xml':""}