diff --git a/HISTORY.rst b/HISTORY.rst index 37823e3..4fc5d75 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,3 +7,10 @@ History ++++++++++++++++++ * First release on PyPI. + + +1.0.1 (2021-12-08) +++++++++++++++++++ + +* Accommodate tenant architecture by checking for a SiteSettings model to see if previous_password_count has been set. +* Second release on PyPI. \ No newline at end of file diff --git a/django_password_history/__init__.py b/django_password_history/__init__.py index 1f356cc..cd7ca49 100644 --- a/django_password_history/__init__.py +++ b/django_password_history/__init__.py @@ -1 +1 @@ -__version__ = '1.0.0' +__version__ = '1.0.1' diff --git a/django_password_history/models.py b/django_password_history/models.py index d20419f..56f1b67 100644 --- a/django_password_history/models.py +++ b/django_password_history/models.py @@ -13,11 +13,21 @@ class UserPasswordHistory(models.Model): password_5 = models.CharField(blank=True, null=True, max_length=128) updated_at = models.DateTimeField(auto_now=True) - def password_is_used(self, password): - if settings.PREVIOUS_PASSWORD_COUNT: - previous_passwords_count = settings.PREVIOUS_PASSWORD_COUNT + def password_is_used(self, password, site_id=1): + previous_passwords_count = 5 + SiteSettings = None + + use_site_setting_password_history = getattr(settings,"USE_SITE_SETTINGS_PASSWORD_HISTORY",False) + + try: + SiteSettings = apps.get_model("setup","SiteSettings") + except: + SiteSettings = None + + if use_site_setting_password_history and SiteSettings: + previous_passwords_count = SiteSettings.objects.get(id=site_id).previous_password_count else: - previous_passwords_count = 5 + previous_passwords_count = getattr(settings,"PREVIOUS_PASSWORD_COUNT", 5) if previous_passwords_count: for x in range(1, min(previous_passwords_count, 5) + 1): @@ -33,4 +43,4 @@ def store_password(self): self.password_3 = self.password_2 self.password_2 = self.password_1 self.password_1 = self.user.password - self.save() + self.save() \ No newline at end of file