summaryrefslogtreecommitdiff
path: root/postgresqleu/auth.py
diff options
context:
space:
mode:
authorMagnus Hagander2013-11-07 17:34:46 +0000
committerMagnus Hagander2013-11-07 17:34:46 +0000
commit975273c0547d63b37ff00dd5f7763efdeca2617c (patch)
treef9009b86fcc38d23fe793d4be601bf760ab5c121 /postgresqleu/auth.py
parent624bb52657b22ac185cb913f2239a73aacb2d9d8 (diff)
Give a nicer error than internal server error on duplicate email
This can happen in the pgeu system due to some legacy data. We have a constraint in the db preventing it from happen, which turns it into an Internal Server Error. Change that so we instead give a message that tells people to email webmaster@ to get it fixed.
Diffstat (limited to 'postgresqleu/auth.py')
-rw-r--r--postgresqleu/auth.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/postgresqleu/auth.py b/postgresqleu/auth.py
index 3f750b4a..9115bc52 100644
--- a/postgresqleu/auth.py
+++ b/postgresqleu/auth.py
@@ -18,7 +18,7 @@
# directory that's processed before the default django.contrib.admin)
#
-from django.http import HttpResponseRedirect
+from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth import login as django_login
@@ -118,6 +118,23 @@ def auth_receive(request):
user.save()
except User.DoesNotExist, e:
# User not found, create it!
+
+ # NOTE! We have some legacy users where there is a user in
+ # the database with a different userid. Instead of trying to
+ # somehow fix that live, give a proper error message and
+ # have somebody look at it manually.
+ if User.objects.filter(email=data['e'][0]).exists():
+ return HttpResponse("""A user with email %s already exists, but with
+a different username than %s.
+
+This is almost certainly caused by some legacy data in our database.
+Please send an email to webmaster@postgresql.eu, indicating the username
+and email address from above, and we'll manually marge the two accounts
+for you.
+
+We apologize for the inconvenience.
+""" % (data['e'][0], data['u'][0]), content_type='text/plain')
+
user = User(username=data['u'][0],
first_name=data['f'][0],
last_name=data['l'][0],