diff options
author | Yasuhito FUTATSUKI at POEM <futatuki@poem.co.jp> | 2019-06-21 07:51:01 +0900 |
---|---|---|
committer | Yasuhito FUTATSUKI at POEM <futatuki@poem.co.jp> | 2019-06-21 07:51:01 +0900 |
commit | 3d32d14b3929489226106ee935bcbb6242b71866 (patch) | |
tree | 91507de6cf467ed68f63e6d1aa6c29c317ca662f /Mailman/Utils.py | |
parent | 83402ad71a22c272ea825068e496efc7fdcebb86 (diff) | |
parent | a5de21c5b47e37b65f66975e7a8ca82be2bc3de4 (diff) | |
download | mailman2-3d32d14b3929489226106ee935bcbb6242b71866.tar.gz mailman2-3d32d14b3929489226106ee935bcbb6242b71866.tar.xz mailman2-3d32d14b3929489226106ee935bcbb6242b71866.zip |
merge lp:mailman/2.1 up to rev 1817
Diffstat (limited to 'Mailman/Utils.py')
-rw-r--r-- | Mailman/Utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py index 10629fc4..36fbd1f9 100644 --- a/Mailman/Utils.py +++ b/Mailman/Utils.py @@ -1576,3 +1576,33 @@ def banned_domain(email): if not re.search(r'127\.0\.1\.255$', text, re.MULTILINE): return True return False + + +def captcha_display(mlist, lang, captchas): + """Returns a CAPTCHA question, the HTML for the answer box, and + the data to be put into the CSRF token""" + if not lang in captchas: + lang = 'en' + captchas = captchas[lang] + idx = random.randrange(len(captchas)) + question = captchas[idx][0] + box_html = mlist.FormatBox('captcha_answer', size=30) + # Remember to encode the language in the index so that we can get it out + # again! + return (websafe(question), box_html, lang + "-" + str(idx)) + +def captcha_verify(idx, given_answer, captchas): + try: + (lang, idx) = idx.split("-") + idx = int(idx) + except ValueError: + return False + if not lang in captchas: + return False + captchas = captchas[lang] + if not idx in range(len(captchas)): + return False + # Check the given answer. + # We append a `$` to emulate `re.fullmatch`. + correct_answer_pattern = captchas[idx][1] + "$" + return re.match(correct_answer_pattern, given_answer) |