source: captchaauthplugin/0.11/captchaauth/web_ui.py

Last change on this file was 6588, checked in by Jeff Hammel, 14 years ago

separate image captcha display into its own handler

File size: 1.4 KB
Line 
1"""
2PNG image CAPTCHA handler
3"""
4
5from genshi.builder import tag
6
7from skimpyGimpy import skimpyAPI
8
9from trac.config import Option
10from trac.core import *
11from trac.web import IRequestHandler
12
13class ImageCaptcha(Component):
14
15    implements(IRequestHandler)
16    captcha_type = Option('captchaauth', 'type',
17                          default="png")
18
19
20    def match_request(self, req):
21        """Return whether the handler wants to process the given request."""
22        if self.captcha_type == 'png' and req.path_info.strip('/') == 'captcha.png' and 'captcha' in req.session:
23            return True
24
25
26    def process_request(self, req):
27        """Process the request. For ClearSilver, return a (template_name,
28        content_type) tuple, where `template` is the ClearSilver template to use
29        (either a `neo_cs.CS` object, or the file name of the template), and
30        `content_type` is the MIME type of the content. For Genshi, return a
31        (template_name, data, content_type) tuple, where `data` is a dictionary
32        of substitutions for the template.
33
34        For both templating systems, "text/html" is assumed if `content_type` is
35        `None`.
36
37        Note that if template processing should not occur, this method can
38        simply send the response itself and not return anything.
39        """
40        img = skimpyAPI.Png(req.session['captcha'], scale=2.2).data()
41        req.send(img, 'image/png')
42
Note: See TracBrowser for help on using the repository browser.