Don't 500 when users try to make their name super long.

(imported from commit 0c5e8baa421ed8cbff431bc5085ffe78b0a8fc1e)
This commit is contained in:
Tim Abbott 2013-07-08 10:42:00 -04:00
parent ce365829f1
commit b8c40119a2
2 changed files with 8 additions and 4 deletions

View File

@ -83,10 +83,11 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
bot_owner = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
USERNAME_FIELD = 'email'
MAX_NAME_LENGTH = 100
# Our custom site-specific fields
full_name = models.CharField(max_length=100)
short_name = models.CharField(max_length=100)
full_name = models.CharField(max_length=MAX_NAME_LENGTH)
short_name = models.CharField(max_length=MAX_NAME_LENGTH)
pointer = models.IntegerField()
last_pointer_updater = models.CharField(max_length=64)
realm = models.ForeignKey(Realm)

View File

@ -1367,8 +1367,11 @@ def json_change_settings(request, user_profile, full_name=REQ,
result = {}
if user_profile.full_name != full_name and full_name.strip() != "":
do_change_full_name(user_profile, full_name.strip())
result['full_name'] = full_name
new_full_name = full_name.strip()
if len(new_full_name) > UserProfile.MAX_NAME_LENGTH:
return json_error("Name too long!")
do_change_full_name(user_profile, new_full_name)
result['full_name'] = new_full_name
if user_profile.enable_desktop_notifications != enable_desktop_notifications:
do_change_enable_desktop_notifications(user_profile, enable_desktop_notifications)