Return clean invalid user errors using the API.

(imported from commit 2f1687cbe8797ce42e66b340e87400720acd4054)
This commit is contained in:
Tim Abbott 2012-10-04 15:52:27 -04:00
parent 738fe500f0
commit 27fdb10cbd

View File

@ -46,7 +46,10 @@ def api_key_required(view_func):
# decorator ordering right.
if request.method != "POST":
return HttpResponseBadRequest('This form can only be submitted by POST.')
user_profile = UserProfile.objects.get(user__email=request.POST.get("email"))
try:
user_profile = UserProfile.objects.get(user__email=request.POST.get("email"))
except UserProfile.DoesNotExist:
return json_error("Invalid user")
if user_profile is None or request.POST.get("api-key") != user_profile.api_key:
return json_error('Invalid API user/key pair.')
return view_func(request, user_profile, *args, **kwargs)