| 1 | """ |
|---|
| 2 | PNG image CAPTCHA handler |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | from genshi.builder import tag |
|---|
| 6 | |
|---|
| 7 | from skimpyGimpy import skimpyAPI |
|---|
| 8 | |
|---|
| 9 | from trac.config import Option |
|---|
| 10 | from trac.core import * |
|---|
| 11 | from trac.web import IRequestHandler |
|---|
| 12 | |
|---|
| 13 | class 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 | |
|---|