def handle_github_payload(request): if request.method == 'POST': payload = json.loads(request.POST.get('payload')) fb = FogBugz(settings.FOGBUGZ_URL) fb._token = None commits = payload['commits'] if commits: for c in commits: user = FogBugzLogin.objects.filter( email = c['author']['email']) if user: user = user[0] fb._token = user.fogbugz_token message = c['message'] commit_hash = c['id'] case_ids, fb_message = parse_commit_message(message, commit_hash) try: for case_id in case_ids: post_message(fb, case_id, fb_message, commit_hash) except FogBugzAPIError as e: send_error_email(e.message) break return HttpResponse('Thanks, GitHub!') # we don't want any GET requests on this page. Only POST return HttpResponse('Move along. Nothing to see here.')
def login(request): fogbugz_error = None if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): email_address = str(request.POST.get('email_address','')) password = str(request.POST.get('password','')) fb = FogBugz(settings.FOGBUGZ_URL) try: fb.logon(email_address, password) except FogBugzAPIError as e: fogbugz_error = e.message mail_error = 'Error on login:\n\n' + e.message send_error_email(mail_error) fb_token = fb._token # pylint: disable=W0212 # save token into model if fb_token: login = FogBugzLogin.objects.filter(email=email_address) if not login: login = FogBugzLogin(email=email_address, fogbugz_token=fb_token) login.save() else: login.update(fogbugz_token=fb_token) return render_to_response('fogbugz_login_complete.html') else: form = LoginForm() return render_to_response('login.html', {'login_form': form, 'fogbugz_error': fogbugz_error, 'fogbugz_site': settings.FOGBUGZ_URL})