Send invites

This commit is contained in:
Mouse Reeve 2021-03-21 09:13:21 -07:00
parent 685da1f5b8
commit 1644c421e5
7 changed files with 53 additions and 23 deletions

View file

@ -6,6 +6,16 @@ from bookwyrm import models
from bookwyrm.tasks import app
def invite_email(invite_request):
""" send out an invite code """
site = models.SiteSettings.objects.get()
data = {
"site_name": site.name,
"invite_link": invite_request.invite.link,
}
send_email.delay(invite_request.email, "invite", data)
def password_reset_email(reset_code):
""" generate a password reset email """
site = models.SiteSettings.objects.get()

View file

@ -0,0 +1,2 @@
{% load i18n %}
<a href="{{ invite_link }}">{% blocktrans %}Join {{ site_name }}{% endblocktrans %}</a>

View file

@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}You're invited! Join {{ site_name }}{% endblocktrans %}

View file

@ -0,0 +1,2 @@
{% load i18n %}
{% blocktrans %}Join {{ site_name }}: {{ invite_link }}{% endblocktrans %}

View file

@ -15,8 +15,8 @@
<h2 class="menu-label">{% trans "Manage Users" %}</h2>
<ul class="menu-list">
<li>
{% url 'settings-invites' as url %}
{% url 'settings-invite-requests' as alt_url %}
{% url 'settings-invite-requests' as url %}
{% url 'settings-invites' as alt_url %}
<a href="{{ url }}"{% if url in request.path or request.path in alt_url %} class="is-active" aria-selected="true"{% endif %}>{% trans "Invites" %}</a>
</li>
<li>

View file

@ -49,17 +49,20 @@
{% trans "Requested" %}
{% endif %}
</td>
<td>
{% if req.invite and not req.invite.times_used %}
<button class="button is-danger is-light is-small">{% trans "Revoke invite" %}</button>
{% else %}
<div class="field is-grouped">
<td class="field is-grouped">
<form name="send-invite" method="post" action="{% url 'settings-invite-requests' %}">
{% csrf_token %}
<input type="hidden" name="invite-request" value="{{ req.id }}">
{% if not req.invite %}
<button type="submit" class="button is-link is-light is-small">{% trans "Send invite" %}</button>
{% else %}
<button type="submit" class="button is-link is-light is-small">{% trans "Re-send invite" %}</button>
{% endif %}
</form>
{% if req.invite and not req.invite.times_used %}
{# <button class="button is-danger is-light is-small">{% trans "Revoke invite" %}</button> #}
{% else %}
<form name="ignore-request" method="post" action="{% url 'settings-invite-requests-ignore' %}">
{% csrf_token %}
<input type="hidden" name="invite-request" value="{{ req.id }}">
@ -69,7 +72,6 @@
<button type="submit" class="button is-danger is-light is-small">{% trans "Un-gnore" %}</button>
{% endif %}
</form>
</div>
{% endif %}
</td>
</tr>

View file

@ -8,7 +8,7 @@ from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.http import require_POST
from bookwyrm import forms, models
from bookwyrm import emailing, forms, models
from bookwyrm.settings import PAGE_LENGTH
from . import helpers
@ -107,6 +107,18 @@ class ManageInviteRequests(View):
def post(self, request):
""" send out an invite """
invite_request = get_object_or_404(
models.InviteRequest, id=request.POST.get("invite-request")
)
# allows re-sending invites
invite_request.invite, _ = models.SiteInvite.objects.get_or_create(
use_limit=1,
user=request.user,
)
invite_request.save()
emailing.invite_email(invite_request)
return redirect('settings-invite-requests')
class InviteRequest(View):