prevent account spam
This commit is contained in:
@ -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
|
||||||
|
@ -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')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user