mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 15:00:01 +00:00
Email blacklist (#419)
This commit is contained in:
parent
1f31427e5e
commit
7f9dc622b1
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
|
@ -44,6 +45,19 @@ ENABLE_SHOW_STATS = True
|
||||||
# Depends on email support!
|
# Depends on email support!
|
||||||
ALLOW_PASSWORD_RESET = True
|
ALLOW_PASSWORD_RESET = True
|
||||||
|
|
||||||
|
# A list of strings or compiled regexes to deny registering emails by.
|
||||||
|
# Regexes will be .search()'d against emails,
|
||||||
|
# while strings will be a simple 'string in email.lower()' check.
|
||||||
|
# Leave empty to disable the blacklist.
|
||||||
|
EMAIL_BLACKLIST = (
|
||||||
|
# Hotmail completely rejects "untrusted" emails,
|
||||||
|
# so it's less of a headache to blacklist them as users can't receive the mails anyway.
|
||||||
|
re.compile(r'(?i)@((hotmail|live|msn|outlook|passport)\.com|passport\.net)'),
|
||||||
|
re.compile(r'(?i)@outlook\.(at|be|cl|co\.(id|il|nz|th)|com\.(ar|au|br|gr|pe|tr|vn)|cz|de|dk|es|fr|hu|ie|in|it|jp|kr|lv|my|ph|pt|sa|sg|sk)'),
|
||||||
|
# '@dodgydomain.tk'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Recaptcha keys (https://www.google.com/recaptcha)
|
# Recaptcha keys (https://www.google.com/recaptcha)
|
||||||
RECAPTCHA_PUBLIC_KEY = '***'
|
RECAPTCHA_PUBLIC_KEY = '***'
|
||||||
RECAPTCHA_PRIVATE_KEY = '***'
|
RECAPTCHA_PRIVATE_KEY = '***'
|
||||||
|
|
|
@ -69,6 +69,23 @@ def upload_recaptcha_validator_shim(form, field):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def register_email_validator(form, field):
|
||||||
|
email_blacklist = app.config.get('EMAIL_BLACKLIST', [])
|
||||||
|
email = field.data.strip()
|
||||||
|
validation_exception = StopValidation('Blacklisted email provider')
|
||||||
|
|
||||||
|
for item in email_blacklist:
|
||||||
|
if isinstance(item, re._pattern_type):
|
||||||
|
if item.search(email):
|
||||||
|
raise validation_exception
|
||||||
|
elif isinstance(item, str):
|
||||||
|
if item in email.lower():
|
||||||
|
raise validation_exception
|
||||||
|
else:
|
||||||
|
raise Exception('Unexpected email validator type {!r} ({!r})'.format(type(item), item))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
_username_validator = Regexp(
|
_username_validator = Regexp(
|
||||||
r'^[a-zA-Z0-9_\-]+$',
|
r'^[a-zA-Z0-9_\-]+$',
|
||||||
message='Your username must only consist of alphanumerics and _- (a-zA-Z0-9_-)')
|
message='Your username must only consist of alphanumerics and _- (a-zA-Z0-9_-)')
|
||||||
|
@ -112,6 +129,7 @@ class RegisterForm(FlaskForm):
|
||||||
Email(),
|
Email(),
|
||||||
DataRequired(),
|
DataRequired(),
|
||||||
Length(min=5, max=128),
|
Length(min=5, max=128),
|
||||||
|
register_email_validator,
|
||||||
Unique(User, User.email, 'Email already in use by another account')
|
Unique(User, User.email, 'Email already in use by another account')
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue