Commit 2587edbe authored by fred's avatar fred
Browse files

misc: handle existing subscribers by resetting existing data

parent 51b4b1bb
...@@ -28,19 +28,26 @@ from ckeditor.fields import RichTextField ...@@ -28,19 +28,26 @@ from ckeditor.fields import RichTextField
class Subscriber(models.Model) : 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) 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_validated = models.NullBooleanField()
is_registered = models.NullBooleanField() # À l'inscription après la confirmation Null si erreur à l'envoi à mailman. is_registered = models.NullBooleanField()
password = models.CharField(max_length=100) # sha1 password = models.CharField(max_length=100)
def __unicode__(self) : def __unicode__(self) :
return return
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super(Subscriber, self).save(*args, **kwargs) existing_subscriber = self.objects.filter(
if self.is_validated is None: if existing_subscriber and !=
self.send_confirmation_email() # reset existing subscriber
existing_subscriber.is_validated = None
existing_subscriber.is_registered = None
super(Subscriber, self).save(*args, **kwargs)
if self.is_validated is None:
def send_confirmation_email(self): def send_confirmation_email(self):
self.password = hashlib.sha1(force_bytes(str(random.random()))).hexdigest() self.password = hashlib.sha1(force_bytes(str(random.random()))).hexdigest()
Supports Markdown
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