1
0
Fork 0

Adds username/localname fields

This commit is contained in:
Mouse Reeve 2020-01-27 20:56:45 -08:00
parent 8dfad68ca7
commit b2b651a22f
5 changed files with 34 additions and 14 deletions

View file

@ -15,6 +15,12 @@ class User(AbstractUser):
api_key = models.CharField(max_length=255, blank=True, null=True)
actor = models.CharField(max_length=255)
local = models.BooleanField(default=True)
localname = models.CharField(
max_length=255,
null=True,
blank=True,
unique=True
)
# TODO: a field for if non-local users are readers or others
followers = models.ManyToManyField('self', symmetrical=False)
created_date = models.DateTimeField(auto_now_add=True)
@ -28,11 +34,16 @@ class User(AbstractUser):
self.private_key = key.export_key().decode('utf8')
self.public_key = key.publickey().export_key().decode('utf8')
if self.local and not self.actor:
self.actor = 'https://%s/api/u/%s' % (DOMAIN, self.username)
if self.local and not re.match(r'\w+@\w+.\w+', self.username):
# set your local username that doesn't have the domain
self.username = '%s@%s' % (self.username, DOMAIN)
if self.local and not self.localname:
self.localname = self.username.replace('@%s' % DOMAIN, '')
if self.local and not self.actor:
self.actor = 'https://%s/api/u/%s' % (DOMAIN, self.localname)
super().save(*args, **kwargs)
@ -137,7 +148,7 @@ class Shelf(models.Model):
def save(self, *args, **kwargs):
if not self.identifier:
self.identifier = '%s_%s' % (
self.user.username,
self.user.localname,
re.sub(r'\W', '-', self.name).lower()
)
if not self.activitypub_id: