Commit 2587edbe authored by fred's avatar fred

misc: handle existing subscribers by resetting existing data

parent 51b4b1bb
......@@ -28,19 +28,26 @@ from ckeditor.fields import RichTextField
class Subscriber(models.Model) :
email = models.EmailField(unique = True) # TODO : informer si déjà inscrit ? Que faire dans ce cas.
email = models.EmailField(unique=True)
inscription_date = models.DateField(auto_now_add=True)
is_validated = models.NullBooleanField() # Au click sur le lien de confirmation. Null si erreur à l'envoi au souscripteur.
is_registered = models.NullBooleanField() # À l'inscription après la confirmation Null si erreur à l'envoi à mailman.
password = models.CharField(max_length=100) # sha1
is_validated = models.NullBooleanField()
is_registered = models.NullBooleanField()
password = models.CharField(max_length=100)
def __unicode__(self) :
return self.email
def save(self, *args, **kwargs):
super(Subscriber, self).save(*args, **kwargs)
if self.is_validated is None:
self.send_confirmation_email()
existing_subscriber = self.objects.filter(email=self.email).first()
if existing_subscriber and existing_subscriber.id != self.id:
# reset existing subscriber
existing_subscriber.is_validated = None
existing_subscriber.is_registered = None
existing_subscriber.save()
else:
super(Subscriber, self).save(*args, **kwargs)
if self.is_validated is None:
self.send_confirmation_email()
def send_confirmation_email(self):
self.password = hashlib.sha1(force_bytes(str(random.random()))).hexdigest()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment