Commit bbc87811 by Michael Hall

Strict username requirements, if there is no openid nickname, of a conflict with…

Strict username requirements, if there is no openid nickname, of a conflict with an existing Django username, fail it
parent 7069378a
......@@ -42,7 +42,9 @@ from django_openid_auth.models import UserOpenID
class IdentityAlreadyClaimed(Exception):
pass
class StrictUsernameViolation(Exception):
pass
class OpenIDBackend:
"""A django.contrib.auth backend that authenticates the user based on
an OpenID response."""
......@@ -72,7 +74,10 @@ class OpenIDBackend:
claimed_id__exact=openid_response.identity_url)
except UserOpenID.DoesNotExist:
if getattr(settings, 'OPENID_CREATE_USERS', False):
user = self.create_user_from_openid(openid_response)
try:
user = self.create_user_from_openid(openid_response)
except StrictUsernameViolation:
return None
else:
user = user_openid.user
......@@ -141,6 +146,12 @@ class OpenIDBackend:
nickname = details['nickname'] or 'openiduser'
email = details['email'] or ''
if getattr(settings, 'OPENID_STRICT_USERNAMES', False):
if details['nickname'] is None or details['nickname'] == '':
raise StrictUsernameViolation()
if User.objects.filter(username__exact=nickname).count() > 0:
raise StrictUsernameViolation()
# Pick a username for the user based on their nickname,
# checking for conflicts.
i = 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment