Fixes logic issues in saving user model

This commit is contained in:
Mouse Reeve 2020-11-01 12:07:51 -08:00
parent beb5e1f11e
commit a2692f92d2
3 changed files with 11 additions and 6 deletions

View file

@ -172,13 +172,13 @@ class User(OrderedCollectionPageMixin, AbstractUser):
''' populate fields for new local users '''
# this user already exists, no need to populate fields
if self.id:
return
return super().save(*args, **kwargs)
if not self.local:
# generate a username that uses the domain (webfinger format)
actor_parts = urlparse(self.remote_id)
self.username = '%s@%s' % (self.username, actor_parts.netloc)
return
return super().save(*args, **kwargs)
# populate fields for local users
self.remote_id = 'https://%s/user/%s' % (DOMAIN, self.username)
@ -191,7 +191,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
if not self.private_key:
self.private_key, self.public_key = create_key_pair()
super().save(*args, **kwargs)
return super().save(*args, **kwargs)
@receiver(models.signals.post_save, sender=User)

View file

@ -37,10 +37,15 @@ def outbox(request, username):
def handle_remote_webfinger(query):
''' webfingerin' other servers, username query should be user@domain '''
''' webfingerin' other servers '''
user = None
# usernames could be @user@domain or user@domain
if query[0] == '@':
query = query[1:]
try:
domain = query.split('@')[2]
domain = query.split('@')[1]
except IndexError:
return None

View file

@ -27,7 +27,7 @@
</a>
<form class="navbar-item" action="/search/">
<div class="field is-grouped">
<input class="input" type="text" name="q" placeholder="Search for a book or user">
<input class="input" type="text" name="q" placeholder="Search for a book or user" value="{{ query }}">
<button class="button" type="submit">
<span class="icon icon-search">
<span class="is-sr-only">search</span>