diff --git a/cookbook/helper/AllAuthCustomAdapter.py b/cookbook/helper/AllAuthCustomAdapter.py index 1823265f0..9587cf2a0 100644 --- a/cookbook/helper/AllAuthCustomAdapter.py +++ b/cookbook/helper/AllAuthCustomAdapter.py @@ -1,6 +1,11 @@ +import datetime + from django.conf import settings from allauth.account.adapter import DefaultAccountAdapter +from django.contrib import messages +from django.core.cache import caches +from gettext import gettext as _ class AllAuthCustomAdapter(DefaultAccountAdapter): @@ -17,6 +22,11 @@ class AllAuthCustomAdapter(DefaultAccountAdapter): # disable password reset for now def send_mail(self, template_prefix, email, context): if settings.EMAIL_HOST != '': - super(AllAuthCustomAdapter, self).send_mail(template_prefix, email, context) + default = datetime.datetime.now() + c = caches['default'].get_or_set(email, default, timeout=360) + if c == default: + super(AllAuthCustomAdapter, self).send_mail(template_prefix, email, context) + else: + messages.add_message(self.request, messages.ERROR, _('In order to prevent spam, the requested email was not send. Please wait a few minutes and try again.')) else: pass diff --git a/recipes/settings.py b/recipes/settings.py index 4591d9a5d..7848b08fc 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -242,6 +242,13 @@ else: # } # } +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', + 'LOCATION': 'default', + } +} + # Vue webpack settings VUE_DIR = os.path.join(BASE_DIR, 'vue')