diff options
author | Andrew Godwin | 2022-11-24 16:27:21 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-24 16:28:47 -0700 |
commit | 3a608c2012b610a8f9b7e5179dcb93ab2e767251 (patch) | |
tree | 131aef3583d68c0448ae0efe557e968b19ab6c45 /users/models | |
parent | ec634f2ad382f659eedae884154d0db9a2a006b2 (diff) | |
download | takahe-3a608c2012b610a8f9b7e5179dcb93ab2e767251.tar.gz takahe-3a608c2012b610a8f9b7e5179dcb93ab2e767251.tar.bz2 takahe-3a608c2012b610a8f9b7e5179dcb93ab2e767251.zip |
Ensure usernames and domains are lowercase
Diffstat (limited to 'users/models')
-rw-r--r-- | users/models/domain.py | 5 | ||||
-rw-r--r-- | users/models/identity.py | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/users/models/domain.py b/users/models/domain.py index c238025..40a3e22 100644 --- a/users/models/domain.py +++ b/users/models/domain.py @@ -59,13 +59,14 @@ class Domain(models.Model): @classmethod def get_remote_domain(cls, domain: str) -> "Domain": - return cls.objects.get_or_create(domain=domain, local=False)[0] + return cls.objects.get_or_create(domain=domain.lower(), local=False)[0] @classmethod def get_domain(cls, domain: str) -> Optional["Domain"]: try: return cls.objects.get( - models.Q(domain=domain) | models.Q(service_domain=domain) + models.Q(domain=domain.lower()) + | models.Q(service_domain=domain.lower()) ) except cls.DoesNotExist: return None diff --git a/users/models/identity.py b/users/models/identity.py index cfa8c2c..7730c8f 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -153,6 +153,7 @@ class Identity(StatorModel): if username.startswith("@"): raise ValueError("Username must not start with @") username = username.lower() + domain = domain.lower() try: if local: return cls.objects.get(username=username, domain_id=domain, local=True) @@ -300,7 +301,7 @@ class Identity(StatorModel): Given a username@domain handle, returns a tuple of (actor uri, canonical handle) or None, None if it does not resolve. """ - domain = handle.split("@")[1] + domain = handle.split("@")[1].lower() try: response = await SystemActor().signed_request( method="get", @@ -381,7 +382,7 @@ class Identity(StatorModel): ) if webfinger_handle: webfinger_username, webfinger_domain = webfinger_handle.split("@") - self.username = webfinger_username + self.username = webfinger_username.lower() self.domain = await get_domain(webfinger_domain) else: self.domain = await get_domain(actor_url_parts.hostname) |