def result(request): if request.method == 'POST': return error403(request) if 'job_id' not in request.GET: return error400(request) else: job_id = request.GET.get('job_id') if not job_id: return HttpResponseRedirect('/') if len(job_id) != 16 or (not re.match('[0-9a-fA-F]{16}', job_id)): return error400(request) if 'json' in request.GET and request.GET.get( 'json').lower() != 'false': return result_json(job_id) try: job_list_entry = JobIDs.objects.get(job_id=job_id) except: return error404(request) form = Design1DForm() if job_list_entry.type == "1" else ( Design2DForm() if job_list_entry.type == "2" else Design3DForm()) json = { 'result_job_id': job_id, '%sd_form' % job_list_entry.type: form } return render(request, PATH.HTML_PATH['design_%sd' % job_list_entry.type], json)
def user_login(request): if request.user.is_authenticated(): if 'next' in request.GET and 'admin' in request.GET.get('next'): return error403(request) return HttpResponseRedirect('/group/') if request.method == 'POST': form = LoginForm(request.POST) messages = 'Invalid username and/or password. Please try again.' if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] flag = form.cleaned_data['flag'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) if flag == "Admin": return HttpResponseRedirect('/admin/') else: return HttpResponseRedirect('/group/') else: messages = 'Inactive/disabled account. Please contact us.' return render(request, PATH.HTML_PATH['login'], {'form': form, 'messages': messages}) else: if 'next' in request.GET and 'admin' in request.GET.get('next'): flag = 'Admin' else: flag = 'Member' form = LoginForm(initial={'flag': flag}) return render(request, PATH.HTML_PATH['login'], {'form': form})
def result(request): if request.method != 'GET': return error403(request) if 'job_id' not in request.GET: return error400(request) job_id = request.GET.get('job_id') if len(job_id) != 16 or (not re.match('[0-9a-fA-F]{16}', job_id)): return error400(request) response = result_json(job_id) response['Access-Control-Allow-Origin'] = request.META.get('HTTP_ORIGIN') response['Access-Control-Allow-Methods'] = 'GET' return response
def git_hook(request): if request.method != 'POST': return error404(request) if ('HTTP_X_HUB_SIGNATURE' not in request.META) or ( 'HTTP_X_GITHUB_DELIVERY' not in request.META) or ('HTTP_X_GITHUB_EVENT' not in request.META): return error400(request) signature = request.META['HTTP_X_HUB_SIGNATURE'] mac = hmac.new(env('GITHOOK_SECRET'), msg=request.body, digestmod=sha1) if not hmac.compare_digest('sha1=' + str(mac.hexdigest()), str(signature)): return error403(request) try: call_command('dist') except Exception: print traceback.format_exc() return error500(request) return HttpResponse(content="", status=201)
def submit(request): if not ('HTTP_ORIGIN' in request.META and request.META.get('HTTP_ORIGIN') in ALLOWED_ORIGIN): return error403(request) if request.method != 'POST' or ('type' not in request.POST) or ( request.POST.get('type') not in ('1', '2', '3')): return error400(request) job_type = int(request.POST.get('type')) if job_type == 1: response = design_1d_run(request) elif job_type == 2: response = design_2d_run(request) elif job_type == 3: response = design_3d_run(request) response['Access-Control-Allow-Origin'] = request.META.get('HTTP_ORIGIN') response['Access-Control-Allow-Methods'] = 'POST, OPTIONS' return response