def challenge(self, request): realm = getattr(settings, 'API_AUTH_REALM', 'Restricted access') response = TemplateResponse(request, 'api/401.html') response['WWW-Authenticate'] = 'Basic realm="%s"' % realm response.status_code = 401 return response
def unauthed(self, request): response = TemplateResponse( request=request, template='aldryn_sso/basicauth_auth_required.html', content_type='text/html', ) response['WWW-Authenticate'] = 'Basic realm="Protected"' response.status_code = 401 return response
def challenge(self, request): realm = getattr(settings, 'API_AUTH_REALM', 'Restricted access') response = TemplateResponse( request, 'api/401.html' ) response['WWW-Authenticate'] = 'Basic realm="%s"' % realm response.status_code = 401 return response
def _create_403_response(self, request, operation, resource, authority=None, template_name=None, message=None): template_name = template_name or '403.html' response = TemplateResponse(request, template_name, { 'operation': operation, 'resource': resource, 'authority': authority, 'message': message, 'status_code': '403' }) response.status_code = 403 return response
def browsable_response(request, response, status_code=200): template = "worf/api.html" context = dict( content=response.content.decode("utf-8"), response=response, settings=settings, ) response = TemplateResponse(request, template, context=context) response.status_code = status_code response.render() return response
def confirmed(request): comment = None if 'c' in request.GET: try: comment = get_model().objects.get(pk=request.GET['c']) except ObjectDoesNotExist: pass response = TemplateResponse(request, template, { 'comment': comment, 'is_ajax': is_ajax, 'success': True }) response.status_code = comment.is_public and 201 or 202 return response
def post(self, request): if request.POST['ik_pm_no']: payment_id = request.POST['ik_pm_no'] payment = Payment.objects.get(paymentid=payment_id) payment.status = request.POST['ik_inv_st'] payment.system = request.POST['ik_pw_via'] payment.amount = request.POST['ik_am'] payment.save() self.sendmail(payment) response = TemplateResponse( request, self.get_template(payment), {'payment': payment, 'link': self.get_link(payment), }) response.status_code = '200' return response
def confirmed(request): comment = None if 'c' in request.GET: try: comment = get_model().objects.get(pk=request.GET['c']) except ObjectDoesNotExist: pass response = TemplateResponse(request, template, { 'comment': comment, 'is_ajax': is_ajax, 'success' : True }) response.status_code = comment.is_public and 201 or 202 return response
def simple_browse(request): response_code = None context = {} try: objs = _objects_by_type(REPO.SimpleCollection, SimpleCollection) objs = sorted(objs, key=lambda s: s.label) context['objs'] = objs except RequestFailed: response_code = 500 # FIXME: this is duplicate logic from generic search view context['server_error'] = 'There was an error ' + \ 'contacting the digital repository. This ' + \ 'prevented us from completing your search. If ' + \ 'this problem persists, please alert the ' + \ 'repository administrator.' response = TemplateResponse(request, 'collection/simple_browse.html', context) if response_code is not None: response.status_code = response_code return response
def page_not_found(request): response = TemplateResponse(request, 'page/404.html', {}) response.status_code = 404 return response.render()
except OAuthError, ex: return send_oauth_error(ex) if request.method == 'GET': response = TemplateResponse( request, 'api/auth/oauth/authorise.html', { 'form': AuthoriseForm(), 'app': app, 'no_login_form': True, 'popup': True } ) response.status_code = 401 response.realm = 'API' return response elif request.method == 'POST': callback = app.callback_url form = AuthoriseForm(data = request.POST) if request.user.is_authenticated(): token = oauth_server.authorize_token(token, request.user) if callback: args = '?%s' % token.to_string(only_key = True) return HttpResponseRedirect(callback + args) else: return HttpResponse(token.to_string(only_key = True), mimetype = 'text/plain')
def handle_error(request): response = TemplateResponse(request, 'page/500.html', {}) response.status_code = 500 return response.render()
def handler404(request, exception=None): response = TemplateResponse(request, '404.html', {}) response.status_code = 404 return response
try: token = oauth_server.fetch_request_token(oauth_request) except OAuthError, ex: return send_oauth_error(ex) if request.method == 'GET': response = TemplateResponse( request, 'api/auth/oauth/authorise.html', { 'form': AuthoriseForm(), 'app': app, 'no_login_form': True, 'popup': True }) response.status_code = 401 response.realm = 'API' return response elif request.method == 'POST': callback = app.callback_url form = AuthoriseForm(data=request.POST) if request.user.is_authenticated(): token = oauth_server.authorize_token(token, request.user) if callback: args = '?%s' % token.to_string(only_key=True) return HttpResponseRedirect(callback + args) else: return HttpResponse(token.to_string(only_key=True),
def _get_forbidden_rsponse(request): response = TemplateResponse(request, "403.html") response.status_code = HttpResponseForbidden.status_code return response