Skip to content

Commit b5fcc2c

Browse files
committed
case-insensitive aliases
1 parent dca848a commit b5fcc2c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

drfpasswordless/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
__title__ = 'drfpasswordless'
4-
__version__ = '1.5.3'
4+
__version__ = '1.5.4'
55
__author__ = 'Aaron Ng'
66
__license__ = 'MIT'
77
__copyright__ = 'Copyright 2020 Aaron Ng'

drfpasswordless/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION = (1, 5, 3)
1+
VERSION = (1, 5, 4)
22

33
__version__ = '.'.join(map(str, VERSION))

drfpasswordless/serializers.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ def validate(self, attrs):
4343

4444
if api_settings.PASSWORDLESS_REGISTER_NEW_USERS is True:
4545
# If new aliases should register new users.
46-
user, user_created = User.objects.get_or_create(
47-
**{self.alias_type: alias})
48-
49-
if user_created:
46+
try:
47+
user = User.objects.get(**{self.alias_type+'__iexact': alias})
48+
except User.DoesNotExist:
49+
user = User.objects.create(**{self.alias_type: alias})
5050
user.set_unusable_password()
5151
user.save()
5252
else:
5353
# If new aliases should not register new users.
5454
try:
55-
user = User.objects.get(**{self.alias_type: alias})
55+
user = User.objects.get(**{self.alias_type+'__iexact': alias})
5656
except User.DoesNotExist:
5757
user = None
5858

@@ -202,7 +202,7 @@ def validate(self, attrs):
202202
try:
203203
alias_type, alias = self.validate_alias(attrs)
204204
callback_token = attrs.get('token', None)
205-
user = User.objects.get(**{alias_type: alias})
205+
user = User.objects.get(**{alias_type+'__iexact': alias})
206206
token = CallbackToken.objects.get(**{'user': user,
207207
'key': callback_token,
208208
'type': CallbackToken.TOKEN_TYPE_AUTH,
@@ -252,7 +252,7 @@ def validate(self, attrs):
252252
try:
253253
alias_type, alias = self.validate_alias(attrs)
254254
user_id = self.context.get("user_id")
255-
user = User.objects.get(**{'id': user_id, alias_type: alias})
255+
user = User.objects.get(**{'id': user_id, alias_type+'__iexact': alias})
256256
callback_token = attrs.get('token', None)
257257

258258
token = CallbackToken.objects.get(**{'user': user,

0 commit comments

Comments
 (0)