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,6 +42,8 @@ from django_openid_auth.models import UserOpenID ...@@ -42,6 +42,8 @@ from django_openid_auth.models import UserOpenID
class IdentityAlreadyClaimed(Exception): class IdentityAlreadyClaimed(Exception):
pass pass
class StrictUsernameViolation(Exception):
pass
class OpenIDBackend: class OpenIDBackend:
"""A django.contrib.auth backend that authenticates the user based on """A django.contrib.auth backend that authenticates the user based on
...@@ -72,7 +74,10 @@ class OpenIDBackend: ...@@ -72,7 +74,10 @@ class OpenIDBackend:
claimed_id__exact=openid_response.identity_url) claimed_id__exact=openid_response.identity_url)
except UserOpenID.DoesNotExist: except UserOpenID.DoesNotExist:
if getattr(settings, 'OPENID_CREATE_USERS', False): if getattr(settings, 'OPENID_CREATE_USERS', False):
try:
user = self.create_user_from_openid(openid_response) user = self.create_user_from_openid(openid_response)
except StrictUsernameViolation:
return None
else: else:
user = user_openid.user user = user_openid.user
...@@ -141,6 +146,12 @@ class OpenIDBackend: ...@@ -141,6 +146,12 @@ class OpenIDBackend:
nickname = details['nickname'] or 'openiduser' nickname = details['nickname'] or 'openiduser'
email = details['email'] or '' 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, # Pick a username for the user based on their nickname,
# checking for conflicts. # checking for conflicts.
i = 1 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