Adds email confirmation code field

This commit is contained in:
Mouse Reeve 2021-08-06 14:42:18 -07:00
parent 1126f47224
commit 3e2f1806e9
4 changed files with 62 additions and 9 deletions

View file

@ -0,0 +1,51 @@
# Generated by Django 3.2.4 on 2021-08-06 21:41
import bookwyrm.models.base_model
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0081_alter_user_last_active_date"),
]
operations = [
migrations.AddField(
model_name="user",
name="confirmation_code",
field=models.CharField(
default=bookwyrm.models.base_model.new_access_code, max_length=32
),
),
migrations.AlterField(
model_name="connector",
name="deactivation_reason",
field=models.CharField(
blank=True,
choices=[
("pending", "Pending"),
("self_deletion", "Self Deletion"),
("moderator_deletion", "Moderator Deletion"),
("domain_block", "Domain Block"),
],
max_length=255,
null=True,
),
),
migrations.AlterField(
model_name="user",
name="deactivation_reason",
field=models.CharField(
blank=True,
choices=[
("pending", "Pending"),
("self_deletion", "Self Deletion"),
("moderator_deletion", "Moderator Deletion"),
("domain_block", "Domain Block"),
],
max_length=255,
null=True,
),
),
]

View file

@ -1,4 +1,6 @@
""" base model with default fields """ """ base model with default fields """
import base64
from Crypto import Random
from django.db import models from django.db import models
from django.dispatch import receiver from django.dispatch import receiver
@ -9,6 +11,7 @@ from .fields import RemoteIdField
DeactivationReason = models.TextChoices( DeactivationReason = models.TextChoices(
"DeactivationReason", "DeactivationReason",
[ [
"pending",
"self_deletion", "self_deletion",
"moderator_deletion", "moderator_deletion",
"domain_block", "domain_block",
@ -16,6 +19,11 @@ DeactivationReason = models.TextChoices(
) )
def new_access_code():
"""the identifier for a user invite"""
return base64.b32encode(Random.get_random_bytes(5)).decode("ascii")
class BookWyrmModel(models.Model): class BookWyrmModel(models.Model):
"""shared fields""" """shared fields"""

View file

@ -1,8 +1,6 @@
""" the particulars for this instance of BookWyrm """ """ the particulars for this instance of BookWyrm """
import base64
import datetime import datetime
from Crypto import Random
from django.db import models, IntegrityError from django.db import models, IntegrityError
from django.dispatch import receiver from django.dispatch import receiver
from django.utils import timezone from django.utils import timezone
@ -10,7 +8,7 @@ from model_utils import FieldTracker
from bookwyrm.preview_images import generate_site_preview_image_task from bookwyrm.preview_images import generate_site_preview_image_task
from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES from bookwyrm.settings import DOMAIN, ENABLE_PREVIEW_IMAGES
from .base_model import BookWyrmModel from .base_model import BookWyrmModel, new_access_code
from .user import User from .user import User
@ -61,11 +59,6 @@ class SiteSettings(models.Model):
return default_settings return default_settings
def new_access_code():
"""the identifier for a user invite"""
return base64.b32encode(Random.get_random_bytes(5)).decode("ascii")
class SiteInvite(models.Model): class SiteInvite(models.Model):
"""gives someone access to create an account on the instance""" """gives someone access to create an account on the instance"""

View file

@ -22,7 +22,7 @@ from bookwyrm.signatures import create_key_pair
from bookwyrm.tasks import app from bookwyrm.tasks import app
from bookwyrm.utils import regex from bookwyrm.utils import regex
from .activitypub_mixin import OrderedCollectionPageMixin, ActivitypubMixin from .activitypub_mixin import OrderedCollectionPageMixin, ActivitypubMixin
from .base_model import BookWyrmModel, DeactivationReason from .base_model import BookWyrmModel, DeactivationReason, new_access_code
from .federated_server import FederatedServer from .federated_server import FederatedServer
from . import fields, Review from . import fields, Review
@ -123,6 +123,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
deactivation_reason = models.CharField( deactivation_reason = models.CharField(
max_length=255, choices=DeactivationReason.choices, null=True, blank=True max_length=255, choices=DeactivationReason.choices, null=True, blank=True
) )
confirmation_code = models.CharField(max_length=32, default=new_access_code)
name_field = "username" name_field = "username"
property_fields = [("following_link", "following")] property_fields = [("following_link", "following")]