1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-07-04 12:52:15 +02:00

Confirm email addresses

This commit is contained in:
Yohann D'ANELLO
2020-09-22 19:37:37 +02:00
parent 3741557200
commit ae56203970
14 changed files with 238 additions and 43 deletions

View File

@ -1,7 +1,13 @@
from django.contrib.sites.models import Site
from django.db import models
from django.template import loader
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from django.utils.translation import gettext_lazy as _
from polymorphic.models import PolymorphicModel
from corres2math.tokens import email_validation_token
class Registration(PolymorphicModel):
user = models.OneToOneField(
@ -15,6 +21,36 @@ class Registration(PolymorphicModel):
verbose_name=_("Grant Animath to contact me in the future about other actions"),
)
email_confirmed = models.BooleanField(
default=False,
verbose_name=_("email confirmed"),
)
def save(self, *args, **kwargs):
self.send_email_validation_link()
return super().save(*args, **kwargs)
def send_email_validation_link(self):
subject = "[Corres2math] " + str(_("Activate your Correspondances account"))
token = email_validation_token.make_token(self.user)
uid = urlsafe_base64_encode(force_bytes(self.user.pk))
site = Site.objects.first()
message = loader.render_to_string('registration/mails/email_validation_email.txt',
{
'user': self.user,
'domain': site.domain,
'token': token,
'uid': uid,
})
html = loader.render_to_string('registration/mails/email_validation_email.html',
{
'user': self.user,
'domain': site.domain,
'token': token,
'uid': uid,
})
self.user.email_user(subject, message, html_message=html)
@property
def type(self):
raise NotImplementedError