Skip to content

Commit

Permalink
extend the recaptha validator to make it optional
Browse files Browse the repository at this point in the history
  • Loading branch information
aronwk-aaron committed Nov 17, 2023
1 parent 7633053 commit b7e48bb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ def validate_play_key(form, field):
field.data = PlayKey.key_is_valid(key_string=field.data)
return

def validate_recaptcha(form, field):
current_app.logger.info("start validating with recaptcha")
if current_app.config["RECAPTCHA_ENABLE"]:
current_app.logger.info("validating with recaptcha")
return Recaptcha()
current_app.logger.info("skipping validating with recaptcha")
return True
class CustomRecaptcha(Recaptcha):
def __call__(self, form, field):
if not current_app.config.get("RECAPTCHA_ENABLE", False):
return True
return super(CustomRecaptcha, self).__call__(form, field)


class CustomUserManager(UserManager):
Expand All @@ -57,12 +55,12 @@ class CustomRegisterForm(RegisterForm):
]
)
recaptcha = RecaptchaField(
validators=[validate_recaptcha]
validators=[CustomRecaptcha()]
)

class CustomLoginForm(LoginForm):
recaptcha = RecaptchaField(
validators=[validate_recaptcha]
validators=[CustomRecaptcha()]
)

class CreatePlayKeyForm(FlaskForm):
Expand Down

0 comments on commit b7e48bb

Please sign in to comment.