diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2019-08-23 17:14:07 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-09-20 13:52:04 +0200 |
| commit | 226ebb17290b604ef29e82fb5c1fbac3594ac163 (patch) | |
| tree | 6845abde1e47ec7f5d295ab609becce3c7f492a8 /django/conf/__init__.py | |
| parent | 0719edcd5fed56157ffb3323a8f634aa5e8f9a80 (diff) | |
Fixed #28622 -- Allowed specifying password reset link expiration in seconds and deprecated PASSWORD_RESET_TIMEOUT_DAYS.
Diffstat (limited to 'django/conf/__init__.py')
| -rw-r--r-- | django/conf/__init__.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 5731fe912c..b32e56184d 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -9,14 +9,23 @@ for a list of all possible variables. import importlib import os import time +import traceback +import warnings from pathlib import Path +import django from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured +from django.utils.deprecation import RemovedInDjango40Warning from django.utils.functional import LazyObject, empty ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" +PASSWORD_RESET_TIMEOUT_DAYS_DEPRECATED_MSG = ( + 'The PASSWORD_RESET_TIMEOUT_DAYS setting is deprecated. Use ' + 'PASSWORD_RESET_TIMEOUT instead.' +) + class SettingsReference(str): """ @@ -105,6 +114,20 @@ class LazySettings(LazyObject): """Return True if the settings have already been configured.""" return self._wrapped is not empty + @property + def PASSWORD_RESET_TIMEOUT_DAYS(self): + stack = traceback.extract_stack() + # Show a warning if the setting is used outside of Django. + # Stack index: -1 this line, -2 the caller. + filename, _, _, _ = stack[-2] + if not filename.startswith(os.path.dirname(django.__file__)): + warnings.warn( + PASSWORD_RESET_TIMEOUT_DAYS_DEPRECATED_MSG, + RemovedInDjango40Warning, + stacklevel=2, + ) + return self.__getattr__('PASSWORD_RESET_TIMEOUT_DAYS') + class Settings: def __init__(self, settings_module): @@ -137,6 +160,15 @@ class Settings: if not self.SECRET_KEY: raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") + if self.is_overridden('PASSWORD_RESET_TIMEOUT_DAYS'): + if self.is_overridden('PASSWORD_RESET_TIMEOUT'): + raise ImproperlyConfigured( + 'PASSWORD_RESET_TIMEOUT_DAYS/PASSWORD_RESET_TIMEOUT are ' + 'mutually exclusive.' + ) + setattr(self, 'PASSWORD_RESET_TIMEOUT', self.PASSWORD_RESET_TIMEOUT_DAYS * 60 * 60 * 24) + warnings.warn(PASSWORD_RESET_TIMEOUT_DAYS_DEPRECATED_MSG, RemovedInDjango40Warning) + if hasattr(time, 'tzset') and self.TIME_ZONE: # When we can, attempt to validate the timezone. If we can't find # this file, no check happens and it's harmless. @@ -180,6 +212,9 @@ class UserSettingsHolder: def __setattr__(self, name, value): self._deleted.discard(name) + if name == 'PASSWORD_RESET_TIMEOUT_DAYS': + setattr(self, 'PASSWORD_RESET_TIMEOUT', value * 60 * 60 * 24) + warnings.warn(PASSWORD_RESET_TIMEOUT_DAYS_DEPRECATED_MSG, RemovedInDjango40Warning) super().__setattr__(name, value) def __delattr__(self, name): |
