prevent account spam

This commit is contained in:
vabene1111
2021-05-30 16:16:42 +02:00
parent 3c778927e2
commit e05019d2b1
2 changed files with 18 additions and 1 deletions

View File

@ -1,6 +1,11 @@
import datetime
from django.conf import settings from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter 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): class AllAuthCustomAdapter(DefaultAccountAdapter):
@ -17,6 +22,11 @@ class AllAuthCustomAdapter(DefaultAccountAdapter):
# disable password reset for now # disable password reset for now
def send_mail(self, template_prefix, email, context): def send_mail(self, template_prefix, email, context):
if settings.EMAIL_HOST != '': 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: else:
pass pass

View File

@ -242,6 +242,13 @@ else:
# } # }
# } # }
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'default',
}
}
# Vue webpack settings # Vue webpack settings
VUE_DIR = os.path.join(BASE_DIR, 'vue') VUE_DIR = os.path.join(BASE_DIR, 'vue')