mirror of
https://github.com/DarkflameUniverse/NexusDashboard.git
synced 2024-11-25 15:07:18 +00:00
extend the recaptha validator to make it optional
This commit is contained in:
parent
7633053490
commit
b7e48bb656
16
app/forms.py
16
app/forms.py
@ -34,13 +34,11 @@ def validate_play_key(form, field):
|
|||||||
field.data = PlayKey.key_is_valid(key_string=field.data)
|
field.data = PlayKey.key_is_valid(key_string=field.data)
|
||||||
return
|
return
|
||||||
|
|
||||||
def validate_recaptcha(form, field):
|
class CustomRecaptcha(Recaptcha):
|
||||||
current_app.logger.info("start validating with recaptcha")
|
def __call__(self, form, field):
|
||||||
if current_app.config["RECAPTCHA_ENABLE"]:
|
if not current_app.config.get("RECAPTCHA_ENABLE", False):
|
||||||
current_app.logger.info("validating with recaptcha")
|
return True
|
||||||
return Recaptcha()
|
return super(CustomRecaptcha, self).__call__(form, field)
|
||||||
current_app.logger.info("skipping validating with recaptcha")
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class CustomUserManager(UserManager):
|
class CustomUserManager(UserManager):
|
||||||
@ -57,12 +55,12 @@ class CustomRegisterForm(RegisterForm):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
recaptcha = RecaptchaField(
|
recaptcha = RecaptchaField(
|
||||||
validators=[validate_recaptcha]
|
validators=[CustomRecaptcha()]
|
||||||
)
|
)
|
||||||
|
|
||||||
class CustomLoginForm(LoginForm):
|
class CustomLoginForm(LoginForm):
|
||||||
recaptcha = RecaptchaField(
|
recaptcha = RecaptchaField(
|
||||||
validators=[validate_recaptcha]
|
validators=[CustomRecaptcha()]
|
||||||
)
|
)
|
||||||
|
|
||||||
class CreatePlayKeyForm(FlaskForm):
|
class CreatePlayKeyForm(FlaskForm):
|
||||||
|
Loading…
Reference in New Issue
Block a user