Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit 7927ab4

Browse files
committed
Added textcha functionality
1 parent 10ae259 commit 7927ab4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

conference/accounts.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import random
2+
import re
23

34
from django import forms
45
from django.conf import settings
@@ -217,6 +218,7 @@ class NewAccountForm(forms.Form):
217218

218219
# Additional captcha field with simple python questions
219220
# https://github.com/EuroPython/epcon/issues/703
221+
# https://github.com/EuroPython/epcon/issues/823
220222
captcha_question = forms.CharField(widget=forms.HiddenInput)
221223
captcha_answer = forms.CharField()
222224

@@ -243,8 +245,10 @@ def get_random_captcha_question(self):
243245

244246
def clean_captcha_answer(self):
245247
question = self.cleaned_data['captcha_question']
246-
cq = CaptchaQuestion.objects.get(question=question)
247-
if cq.answer.strip() != self.cleaned_data['captcha_answer'].strip():
248+
answer = self.cleaned_data['captcha_answer'].strip()
249+
correct_answers = CaptchaQuestion.objects.get(question=question).answer
250+
answer_regx = re.compile(correct_answers, re.IGNORECASE)
251+
if not answer_regx.match(answer):
248252
raise forms.ValidationError("Sorry, that's a wrong answer")
249253
return self.cleaned_data['captcha_question']
250254

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.19 on 2021-05-07 18:47
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('conference', '0029_talk_availability'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='captchaquestion',
15+
name='answer',
16+
field=models.CharField(max_length=255, verbose_name='answer (use a regular expression\n to capture possible answers e.g.\n "(python|the python programming language)"\n case is ignored)\n '),
17+
),
18+
]

conference/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,12 @@ class NoQuestionsAvailable(Exception):
13441344
pass
13451345

13461346
question = models.CharField(max_length=255)
1347-
answer = models.CharField(max_length=255)
1347+
answer = models.CharField(max_length=255,
1348+
verbose_name='''answer (use a regular expression
1349+
to capture possible answers e.g.
1350+
"(python|the python programming language)"
1351+
case is ignored)
1352+
''')
13481353
enabled = models.BooleanField(default=True)
13491354

13501355
objects = CaptchaQuestionManager()

0 commit comments

Comments
 (0)