forked from mirrors/bookwyrm
Merge pull request #846 from mouse-reeve/track-invite-use
Associate users with their invites
This commit is contained in:
commit
14353f0de7
3 changed files with 23 additions and 0 deletions
21
bookwyrm/migrations/0060_siteinvite_invitees.py
Normal file
21
bookwyrm/migrations/0060_siteinvite_invitees.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 3.1.6 on 2021-04-02 00:14
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("bookwyrm", "0059_user_preferred_timezone"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="siteinvite",
|
||||||
|
name="invitees",
|
||||||
|
field=models.ManyToManyField(
|
||||||
|
related_name="invitees", to=settings.AUTH_USER_MODEL
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -58,6 +58,7 @@ class SiteInvite(models.Model):
|
||||||
use_limit = models.IntegerField(blank=True, null=True)
|
use_limit = models.IntegerField(blank=True, null=True)
|
||||||
times_used = models.IntegerField(default=0)
|
times_used = models.IntegerField(default=0)
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
|
invitees = models.ManyToManyField(User, related_name="invitees")
|
||||||
|
|
||||||
def valid(self):
|
def valid(self):
|
||||||
""" make sure it hasn't expired or been used """
|
""" make sure it hasn't expired or been used """
|
||||||
|
|
|
@ -108,6 +108,7 @@ class Register(View):
|
||||||
)
|
)
|
||||||
if invite:
|
if invite:
|
||||||
invite.times_used += 1
|
invite.times_used += 1
|
||||||
|
invite.invitees.add(user)
|
||||||
invite.save()
|
invite.save()
|
||||||
|
|
||||||
login(request, user)
|
login(request, user)
|
||||||
|
|
Loading…
Reference in a new issue