mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-24 18:14:22 +00:00
Sli
181e74b1d1
* update_spam_database command to update suspicious domains from an external provider * Add a AntiSpamEmailField that deny emails from suspicious domains * Update documentation
19 lines
671 B
Python
19 lines
671 B
Python
import re
|
|
|
|
from django import forms
|
|
from django.core.validators import EmailValidator
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from antispam.models import ToxicDomain
|
|
|
|
|
|
class AntiSpamEmailField(forms.EmailField):
|
|
"""An email field that email addresses with a known toxic domain."""
|
|
|
|
def run_validators(self, value: str):
|
|
super().run_validators(value)
|
|
# Domain part should exist since email validation is guaranteed to run first
|
|
domain = re.search(EmailValidator.domain_regex, value)
|
|
if ToxicDomain.objects.filter(domain=domain[0]).exists():
|
|
raise forms.ValidationError(_("Email domain is not allowed."))
|