mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Add federated users
This commit is contained in:
parent
a9d938fbb2
commit
f031b46b20
4 changed files with 28 additions and 22 deletions
|
@ -15,16 +15,28 @@ from fedireads.settings import DOMAIN
|
||||||
def get_or_create_remote_user(actor):
|
def get_or_create_remote_user(actor):
|
||||||
''' look up a remote user or add them '''
|
''' look up a remote user or add them '''
|
||||||
try:
|
try:
|
||||||
user = models.User.objects.get(actor=actor)
|
return models.User.objects.get(actor=actor)
|
||||||
except models.User.DoesNotExist:
|
except models.User.DoesNotExist:
|
||||||
# TODO: how do you actually correctly learn this?
|
pass
|
||||||
username = '%s@%s' % (actor.split('/')[-1], actor.split('/')[2])
|
|
||||||
user = models.User.objects.create_user(
|
# get the user's info
|
||||||
username,
|
response = requests.get(
|
||||||
'', '',
|
actor,
|
||||||
actor=actor,
|
headers={'Accept': 'application/activity+json'}
|
||||||
local=False
|
)
|
||||||
)
|
data = response.json()
|
||||||
|
|
||||||
|
username = '%s@%s' % (actor.split('/')[-1], actor.split('/')[2])
|
||||||
|
user = models.User.objects.create_user(
|
||||||
|
username, '', '',
|
||||||
|
name=data.get('name'),
|
||||||
|
summary=data.get('summary'),
|
||||||
|
inbox=data['inbox'],
|
||||||
|
outbox=data['outbox'],
|
||||||
|
shared_inbox=data.get('endpoints').get('sharedInbox'),
|
||||||
|
actor=actor,
|
||||||
|
local=False
|
||||||
|
)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 3.0.2 on 2020-01-29 18:40
|
# Generated by Django 3.0.2 on 2020-01-29 19:58
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import django.contrib.auth.models
|
import django.contrib.auth.models
|
||||||
|
@ -32,8 +32,8 @@ class Migration(migrations.Migration):
|
||||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||||
('private_key', models.TextField(blank=True, null=True, unique=True)),
|
('private_key', models.TextField(blank=True, null=True)),
|
||||||
('public_key', models.TextField(blank=True, null=True, unique=True)),
|
('public_key', models.TextField(blank=True, null=True)),
|
||||||
('api_key', models.CharField(blank=True, max_length=255, null=True)),
|
('api_key', models.CharField(blank=True, max_length=255, null=True)),
|
||||||
('actor', models.CharField(max_length=255, unique=True)),
|
('actor', models.CharField(max_length=255, unique=True)),
|
||||||
('inbox', models.CharField(max_length=255, unique=True)),
|
('inbox', models.CharField(max_length=255, unique=True)),
|
||||||
|
|
|
@ -13,8 +13,8 @@ from fedireads.settings import DOMAIN, OL_URL
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
''' a user who wants to read books '''
|
''' a user who wants to read books '''
|
||||||
private_key = models.TextField(blank=True, null=True, unique=True)
|
private_key = models.TextField(blank=True, null=True)
|
||||||
public_key = models.TextField(blank=True, null=True, unique=True)
|
public_key = models.TextField(blank=True, null=True)
|
||||||
api_key = models.CharField(max_length=255, blank=True, null=True)
|
api_key = models.CharField(max_length=255, blank=True, null=True)
|
||||||
actor = models.CharField(max_length=255, unique=True)
|
actor = models.CharField(max_length=255, unique=True)
|
||||||
inbox = models.CharField(max_length=255, unique=True)
|
inbox = models.CharField(max_length=255, unique=True)
|
||||||
|
@ -44,13 +44,7 @@ class User(AbstractUser):
|
||||||
def execute_before_save(sender, instance, *args, **kwargs):
|
def execute_before_save(sender, instance, *args, **kwargs):
|
||||||
''' create shelves for new users '''
|
''' create shelves for new users '''
|
||||||
# this user already exists, no need to poplate fields
|
# this user already exists, no need to poplate fields
|
||||||
if instance.id:
|
if instance.id or not instance.local:
|
||||||
return
|
|
||||||
|
|
||||||
# TODO: how do I know this properly???
|
|
||||||
if not instance.local:
|
|
||||||
instance.inbox = instance.actor = 'inbox'
|
|
||||||
instance.outbox = instance.actor = 'outbox'
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# populate fields for local users
|
# populate fields for local users
|
||||||
|
|
|
@ -20,7 +20,7 @@ urlpatterns = [
|
||||||
# TODO: re_path(r'^.well-known/host-meta/?$', incoming.host_meta),
|
# TODO: re_path(r'^.well-known/host-meta/?$', incoming.host_meta),
|
||||||
|
|
||||||
# ui views
|
# ui views
|
||||||
re_path(r'^/?$', views.home),
|
path(r'', views.home),
|
||||||
re_path(r'^register/?$', views.register),
|
re_path(r'^register/?$', views.register),
|
||||||
re_path(r'^login/?$', views.user_login),
|
re_path(r'^login/?$', views.user_login),
|
||||||
re_path(r'^logout/?$', views.user_logout),
|
re_path(r'^logout/?$', views.user_logout),
|
||||||
|
|
Loading…
Reference in a new issue