| 52 | users = 'ddserver.interface.user:UserManager', |
| 53 | messages = 'ddserver.interface.message:MessageManager') |
| 54 | def wrapped(config, |
| 55 | users, |
| 56 | messages, |
| 57 | *args, |
| 58 | **kwargs): |
| 59 | if config.captcha.enabled: |
| 60 | from recaptcha.client import captcha |
| 61 | |
| 62 | challenge = bottle.request.POST.pop('recaptcha_challenge_field', None) |
| 63 | response = bottle.request.POST.pop('recaptcha_response_field', None) |
| 64 | |
| 65 | if challenge is None or response is None: |
| 66 | messages.error('Captcha values are missing') |
| 67 | bottle.redirect('/') |
| 68 | |
| 69 | result = captcha.submit(challenge, |
| 70 | response, |
| 71 | config.captcha.recaptcha_private_key, |
| 72 | bottle.request.remote_addr) |
| 73 | |
| 74 | if not result.is_valid: |
| 75 | messages.error('Captcha invalid') |
| 76 | bottle.redirect(__on_error__) |
| 77 | |
| 78 | # Call the wrapped function |
| 79 | return func(*args, |
| 80 | **kwargs) |
| 81 | |
| 82 | return wrapped |
| 83 | return wrapper |