Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not require a captcha when using the API #931

Merged
merged 3 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions ihatemoney/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,11 @@ def validate_id(form, field):
)
raise ValidationError(Markup(message))

@classmethod
def enable_captcha(cls):
captchaField = StringField(
_("Which is a real currency: Euro or Petro dollar?"),
validators=[DataRequired()],
)
setattr(cls, "captcha", captchaField)

class ProjectFormWithCaptcha(ProjectForm):
captcha = StringField(
_("Which is a real currency: Euro or Petro dollar?"),
)

def validate_captcha(form, field):
if not field.data.lower() == _("euro"):
Expand Down
1 change: 1 addition & 0 deletions ihatemoney/tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def test_project_creation_with_captcha(self):
assert len(models.Project.query.all()) == 1

def test_api_project_creation_does_not_need_captcha(self):
self.client.get("/")
resp = self.client.post(
"/api/projects",
data={
Expand Down
4 changes: 2 additions & 2 deletions ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
MemberForm,
PasswordReminder,
ProjectForm,
ProjectFormWithCaptcha,
ResetPasswordForm,
UploadForm,
get_billform_for,
Expand Down Expand Up @@ -263,8 +264,7 @@ def authenticate(project_id=None):

def get_project_form():
if current_app.config.get("ENABLE_CAPTCHA", False):
ProjectForm.enable_captcha()

return ProjectFormWithCaptcha()
return ProjectForm()


Expand Down