Browse Source

Small cleanup

rafalp 6 years ago
parent
commit
eb4fd9818b
1 changed files with 8 additions and 3 deletions
  1. 8 3
      misago/users/models/user.py

+ 8 - 3
misago/users/models/user.py

@@ -133,13 +133,18 @@ class UserManager(BaseUserManager):
         email_hash = hash_email(login)
         slug = slugify(login)
         
-        users = list(self.filter(Q(slug=slug) | Q(email_hash=email_hash)))
-        for user in users:
+        queryset = self.filter(Q(slug=slug) | Q(email_hash=email_hash))
+
+        # find user by email hash (more accurate)
+        for user in queryset:
             if user.email_hash == email_hash:
                 return user
-        for user in users:
+
+        # fallback to find user by slug (safe if email hash failed)
+        for user in queryset:
             if user.slug == slug:
                 return user
+
         raise User.DoesNotExist()