How to replace super().save() in MyCustomSignupForm when recaptcha is not confirmed
How to replace super().save() in MyCustomSignupForm when recaptcha is not confirmed
class MyCustomSignupForm(SignupForm):
def save(self, request):
token = request.POST['g-recaptcha-response']
action = "signup"
r_result = recaptcha(request, token, action)
if r_result:
user = super(MyCustomSignupForm, self).save(request)
else:
messages.warning(request, '...robot...')
user = ???
return user
I think the easier approach here is raising an error if the recaptcha failed. You can do that with a guard clause instead of an if/else e.g.:
if not r_result:
raise ValidationError("whatever")
user = super(MyCustomSignupForm, self).save(request)
I'm not sure if this is exactly what you were looking for.