From 8dd8dab270a6cc5d529190ec609458819b2ba56c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 3 Oct 2011 21:30:43 +0200 Subject: [PATCH] fail if username/email already in use --- pandora/user/views.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandora/user/views.py b/pandora/user/views.py index 3274a31e..5f2ea529 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -329,15 +329,22 @@ def editUser(request): user = get_object_or_404_json(models.User, username=data['id']) profile = user.get_profile() if 'email' in data: + if models.User.objects.filter(email=data['email']).exclude(id=user.id).count()>0: + response = json_response(status=403, text='email already in use') + return render_to_json_response(response) user.email = data['email'] if 'level' in data: profile.set_level(data['level']) if 'note' in data: profile.note = data['note'] if 'username' in data: + if models.User.objects.filter(username=data['username']).exclude(id=user.id).count()>0: + response = json_response(status=403, text='username already in use') + return render_to_json_response(response) user.username = data['username'] user.save() profile.save() + response['data'] = models.user_json() return render_to_json_response(response) actions.register(editUser, cache=False)