mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-29 13:01:08 +00:00
parent
bf58e29a54
commit
f7867da7a0
7 changed files with 29 additions and 30 deletions
|
@ -13,6 +13,7 @@ def get_actor(user):
|
||||||
'preferredUsername': user.localname,
|
'preferredUsername': user.localname,
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
'inbox': user.inbox,
|
'inbox': user.inbox,
|
||||||
|
'outbox': '%s/outbox' % user.actor,
|
||||||
'followers': '%s/followers' % user.actor,
|
'followers': '%s/followers' % user.actor,
|
||||||
'following': '%s/following' % user.actor,
|
'following': '%s/following' % user.actor,
|
||||||
'summary': user.summary,
|
'summary': user.summary,
|
||||||
|
@ -23,6 +24,7 @@ def get_actor(user):
|
||||||
},
|
},
|
||||||
'endpoints': {
|
'endpoints': {
|
||||||
'sharedInbox': user.shared_inbox,
|
'sharedInbox': user.shared_inbox,
|
||||||
}
|
},
|
||||||
|
'fedireadsUser': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,10 @@ def handle_account_search(query):
|
||||||
data = response.json()
|
data = response.json()
|
||||||
for link in data['links']:
|
for link in data['links']:
|
||||||
if link['rel'] == 'self':
|
if link['rel'] == 'self':
|
||||||
user = get_or_create_remote_user(link['href'])
|
try:
|
||||||
|
user = get_or_create_remote_user(link['href'])
|
||||||
|
except KeyError:
|
||||||
|
return HttpResponseNotFound()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,23 +29,21 @@ def get_or_create_remote_user(actor):
|
||||||
shared_inbox = data.get('endpoints').get('sharedInbox') if \
|
shared_inbox = data.get('endpoints').get('sharedInbox') if \
|
||||||
data.get('endpoints') else None
|
data.get('endpoints') else None
|
||||||
|
|
||||||
try:
|
# throws a key error if it can't find any of these fields
|
||||||
user = models.User.objects.create_user(
|
user = models.User.objects.create_user(
|
||||||
username,
|
username,
|
||||||
'', '', # email and passwords are left blank
|
'', '', # email and passwords are left blank
|
||||||
actor=actor,
|
actor=actor,
|
||||||
name=data.get('name'),
|
name=data.get('name'),
|
||||||
summary=data.get('summary'),
|
summary=data.get('summary'),
|
||||||
inbox=data['inbox'], #fail if there's no inbox
|
inbox=data['inbox'], #fail if there's no inbox
|
||||||
outbox=data['outbox'], # fail if there's no outbox
|
outbox=data['outbox'], # fail if there's no outbox
|
||||||
shared_inbox=shared_inbox,
|
shared_inbox=shared_inbox,
|
||||||
# TODO: I'm never actually using this for remote users
|
# TODO: I'm never actually using this for remote users
|
||||||
public_key=data.get('publicKey').get('publicKeyPem'),
|
public_key=data.get('publicKey').get('publicKeyPem'),
|
||||||
local=False,
|
local=False,
|
||||||
fedireads_user=False,
|
fedireads_user=data.get('fedireadsUser', False),
|
||||||
)
|
)
|
||||||
except KeyError:
|
|
||||||
return False
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,13 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not is_self %}
|
{% if not is_self %}
|
||||||
{% if not request.user in user.followers.all %}
|
{% if not request.user in user.followers.all %}
|
||||||
<form action="/follow/" method="post">
|
<form action="/follow/{{ user.username }}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="user" value="{{ user.id }}"></input>
|
|
||||||
<input type="submit" value="Follow"></input>
|
<input type="submit" value="Follow"></input>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<form action="/unfollow/" method="post">
|
<form action="/unfollow/{{ user.username }}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="user" value="{{ user.id }}"></input>
|
|
||||||
<input type="submit" value="Unfollow"></input>
|
<input type="submit" value="Unfollow"></input>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
{% for result in results %}
|
{% for result in results %}
|
||||||
<div>
|
<div>
|
||||||
<h2>{{ result.username }}</h2>
|
<h2>{{ result.username }}</h2>
|
||||||
<form action="/follow/" method="post">
|
<form action="/follow/{{ result.username }}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="user" value="{{ result.id }}"></input>
|
|
||||||
<input type="submit" value="Follow"></input>
|
<input type="submit" value="Follow"></input>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -56,8 +56,8 @@ urlpatterns = [
|
||||||
r'^shelve/(?P<username>\w+)/(?P<shelf_id>[\w-]+)/(?P<book_id>\d+)/?$',
|
r'^shelve/(?P<username>\w+)/(?P<shelf_id>[\w-]+)/(?P<book_id>\d+)/?$',
|
||||||
views.shelve
|
views.shelve
|
||||||
),
|
),
|
||||||
re_path(r'^follow/?$', views.follow),
|
re_path(r'^follow/(?P<username>[\w@\.]+)/?$', views.follow),
|
||||||
re_path(r'^unfollow/?$', views.unfollow),
|
re_path(r'^unfollow/(?P<username>[\w@\.]+)/?$', views.unfollow),
|
||||||
re_path(r'^search/?$', views.search),
|
re_path(r'^search/?$', views.search),
|
||||||
re_path(r'^edit_profile/?$', views.edit_profile),
|
re_path(r'^edit_profile/?$', views.edit_profile),
|
||||||
|
|
||||||
|
|
|
@ -274,11 +274,10 @@ def favorite(request, status_id):
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def follow(request):
|
def follow(request, username):
|
||||||
''' follow another user, here or abroad '''
|
''' follow another user, here or abroad '''
|
||||||
to_follow = request.POST.get('user')
|
|
||||||
# should this be an actor rather than an id? idk
|
# should this be an actor rather than an id? idk
|
||||||
to_follow = models.User.objects.get(id=to_follow)
|
to_follow = models.User.objects.get(username=username)
|
||||||
|
|
||||||
outgoing.handle_outgoing_follow(request.user, to_follow)
|
outgoing.handle_outgoing_follow(request.user, to_follow)
|
||||||
user_slug = to_follow.localname if to_follow.localname \
|
user_slug = to_follow.localname if to_follow.localname \
|
||||||
|
|
Loading…
Reference in a new issue