def br(): a_token = request.headers.get('Authorization') try: credentials = parse_auth(a_token) except: raise HTTPResponse('Please provide a Basic Authentication header\n', 403) if not utils.is_authenticated(*credentials): raise HTTPResponse( 'Unauthenticated\n', 403) u_and_c = credentials[0].split('__') user = u_and_c[0] if len(u_and_c) >1: company = u_and_c[1] else: company = user request.creds = utils.LocalEnv() request.creds.user = user request.creds.company = company request.creds.password = credentials[1]
def br(): a_token = request.headers.get('Authorization') try: credentials = parse_auth(a_token) except: raise HTTPResponse('Please provide a Basic Authentication header\n', 403) if not utils.is_authenticated(*credentials): raise HTTPResponse('Unauthenticated\n', 403) u_and_c = credentials[0].split('__') user = u_and_c[0] if len(u_and_c) > 1: company = u_and_c[1] else: company = user request.creds = utils.LocalEnv() request.creds.user = user request.creds.company = company request.creds.password = credentials[1]
def check_auth(request, *args, **kwargs): if request.session.has_key("access_token"): access_token = request.session.get("access_token") try: request.user = TwitterUser.objects.get(token=access_token) except TwitterUser.DoesNotExist: # Let's create a user token = oauth.OAuthToken.from_string(access_token) auth = is_authenticated(token) if auth: creds = simplejson.loads(auth) name = creds.get("screen_name") # Twitter username user = TwitterUser.objects.create_user(username=name, token=access_token) user.save() request.user = user else: # Warning / whatever pass else: request.user = None return function(request, *args, **kwargs)
def check_auth(request, *args, **kwargs): if request.session.has_key('access_token'): access_token = request.session.get('access_token') try: request.user = TwitterUser.objects.get(token=access_token) except TwitterUser.DoesNotExist: # Let's create a user token = oauth.OAuthToken.from_string(access_token) auth = is_authenticated(token) if auth: creds = simplejson.loads(auth) name = creds.get('screen_name') # Twitter username user = TwitterUser.objects.create_user(username=name, token=access_token) user.save() request.user = user else: # Warning / whatever pass else: request.user = None return function(request, *args, **kwargs)