Give a helpful error if API key is wrong length

Trac #1680

(imported from commit 0a50e7a93b37a5a3e74fb99c97a8917d8fbcc8f9)
This commit is contained in:
Scott Feeney
2013-08-20 18:09:49 -04:00
parent b2c89d21ff
commit 141877a06c

View File

@@ -73,7 +73,11 @@ def validate_api_key(email, api_key):
except UserProfile.DoesNotExist: except UserProfile.DoesNotExist:
raise JsonableError("Invalid user: %s" % (email,)) raise JsonableError("Invalid user: %s" % (email,))
if api_key != user_profile.api_key: if api_key != user_profile.api_key:
raise JsonableError("Invalid API key for user '%s'" % (email,)) if len(api_key) != 32:
reason = "Incorrect API key length (keys should be 32 characters long)"
else:
reason = "Invalid API key"
raise JsonableError(reason + " for user '%s'" % (email,))
if not user_profile.is_active: if not user_profile.is_active:
raise JsonableError("User account is not active") raise JsonableError("User account is not active")
return user_profile return user_profile