~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/security/textcha.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    def _get_textchas(self):
47
47
        """ get textchas from the wiki config for the user's language (or default_language or en) """
48
48
        request = self.request
49
 
        groups = request.groups
50
49
        cfg = request.cfg
51
50
        user = request.user
52
51
        disabled_group = cfg.textchas_disabled_group
53
 
        if disabled_group and user.name and user.name in groups.get(disabled_group, []):
 
52
        if disabled_group and user.name and request.dicts.has_member(disabled_group, user.name):
54
53
            return None
55
54
        textchas = cfg.textchas
56
55
        if textchas:
90
89
                self.answer_re = re.compile(self.answer_regex, re.U|re.I)
91
90
            except KeyError:
92
91
                # this question does not exist, thus there is no answer
93
 
                self.answer_regex = ur"[Never match for cheaters]"
94
 
                self.answer_re = None
 
92
                self.answer_regex = ur"[^.]*" # this shall never match!
 
93
                self.answer_re = re.compile(self.answer_regex, re.U|re.I)
95
94
                logging.warning(u"TextCha: Non-existing question '%s'. User '%s' trying to cheat?" % (
96
95
                                self.question, self.user_info))
97
96
            except re.error:
117
116
    def check_answer(self, given_answer):
118
117
        """ check if the given answer to the question is correct """
119
118
        if self.is_enabled():
120
 
            if self.answer_re is not None:
121
 
                success = self.answer_re.match(given_answer.strip()) is not None
122
 
            else:
123
 
                # someone trying to cheat!?
124
 
                success = False
 
119
            success = self.answer_re.match(given_answer.strip()) is not None
125
120
            success_status = success and u"success" or u"failure"
126
121
            logging.info(u"TextCha: %s (u='%s', a='%s', re='%s', q='%s')" % (
127
122
                             success_status,
142
137
    def _extract_form_values(self, form=None):
143
138
        if form is None:
144
139
            form = self.request.form
145
 
        question = form.get('textcha-question')
146
 
        given_answer = form.get('textcha-answer', u'')
 
140
        question = form.get('textcha-question', [None])[0]
 
141
        given_answer = form.get('textcha-answer', [u''])[0]
147
142
        return question, given_answer
148
143
 
149
144
    def render(self, form=None):