def user_info(request): if 'credentials' not in request.session: return HttpResponseRedirect(reverse('home_page')) credentials = client.OAuth2Credentials.from_json(request.session['credentials']) if credentials.access_token_expired: return HttpResponseRedirect(reverse('home_page')) http_auth = credentials.authorize(httplib2.Http()) service = discovery.build('plus', 'v1', http=http_auth) google_request = service.people().get(userId='me') result = google_request.execute(http=http_auth) if 'domain' not in result.keys(): return HttpResponse("Not a valid user to register") elif result['domain'] == "above-inc.com": email = result['emails'][0]['value'] username = email[:-14] password = result['id'] else: return HttpResponse("Nothing") try: saved_user = User.objects.get(username = username,password=password,email = email) except Exception as e: print e saved_user = User(username=username,password=password,email = email) saved_user.save() try: user = authenticate(username=saved_user, password=password) except Exception as e: print e return HTTPResponse("not authenticated") if user is not None: if user.is_active: login(request,user) return HttpResponseRedirect(reverse('userdetails')) else: return HttpResponseRedirect(reverse("home_page")) else: print "some were wrong in else login else" return HttpResponseRedirect(reverse("home_page"))
def request(self, method, path, data, headers): req = webob.Request.blank(path) req.method = method req.body = data req.headers = headers req.headers['Accept'] = 'text/html' req.host = self.host # Call the WSGI app, get the HTTP response resp = str(req.get_response(self.app)) # For some reason, the response doesn't have "HTTP/1.0 " prepended; I # guess that's a function the web server usually provides. resp = "HTTP/1.0 %s" % resp self.sock = FakeHttplibSocket(resp) self.http_response = HTTPResponse(self.sock) # NOTE(vish): boto is accessing private variables for some reason self._HTTPConnection__response = self.http_response self.http_response.begin()
def page404(request): return HTTPResponse("444")