SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 898f6a74 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

add verification token fields to profile emails

parent 3c025f6a
No related branches found
No related tags found
No related merge requests found
# Generated by Django 4.2.10 on 2024-08-15 16:58
import secrets
from django.db import migrations, models
from django.utils import timezone
def reset_profile_email_verification_tokens(apps, schema_editor):
ProfileEmail = apps.get_model("profiles", "ProfileEmail")
for email in ProfileEmail.objects.all():
email.verification_token = secrets.token_urlsafe(40)
email.verified = email.primary and email.still_valid
email.save()
class Migration(migrations.Migration):
dependencies = [
("profiles", "0041_profile_orcid_authenticated"),
]
operations = [
migrations.AddField(
model_name="profileemail",
name="token_expiration",
field=models.DateTimeField(default=timezone.now),
),
migrations.AddField(
model_name="profileemail",
name="verification_token",
field=models.CharField(max_length=128, null=True, unique=False),
),
migrations.RunPython(
reset_profile_email_verification_tokens,
reverse_code=migrations.RunPython.noop,
),
migrations.AlterField(
model_name="profileemail",
name="verification_token",
field=models.CharField(max_length=128, unique=True, null=False),
),
]
......@@ -213,6 +213,8 @@ class ProfileEmail(models.Model):
email = models.EmailField()
still_valid = models.BooleanField(default=True)
verified = models.BooleanField(default=False)
verification_token = models.CharField(max_length=128, unique=True)
token_expiration = models.DateTimeField(default=timezone.now)
added_by = models.ForeignKey(
"scipost.Contributor",
on_delete=models.SET_NULL,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment