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

Commit 7930ee8

Browse files
committed
Added textcha functionality
1 parent 7d2e20d commit 7930ee8

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
@@ -216,6 +217,7 @@ class NewAccountForm(forms.Form):
216217

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

@@ -242,8 +244,10 @@ def get_random_captcha_question(self):
242244

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

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
@@ -1308,7 +1308,12 @@ class NoQuestionsAvailable(Exception):
13081308
pass
13091309

13101310
question = models.CharField(max_length=255)
1311-
answer = models.CharField(max_length=255)
1311+
answer = models.CharField(max_length=255,
1312+
verbose_name='''answer (use a regular expression
1313+
to capture possible answers e.g.
1314+
"(python|the python programming language)"
1315+
case is ignored)
1316+
''')
13121317
enabled = models.BooleanField(default=True)
13131318

13141319
objects = CaptchaQuestionManager()

0 commit comments

Comments
 (0)