Implemented basic extra handling (ie. plug-ins in Antville):

* Added global app.data.extras collection and registerExtra() method
 * Defined res.handlers.extra in HopObject.onRequest() handler to provide extra macros
 * Implemented reCAPTCHA for anonymously contacting an Antville member as proof of concept
This commit is contained in:
Tobi Schäfer 2011-03-23 13:35:02 +00:00
parent 8a83f406f8
commit 91b45b3732
8 changed files with 135 additions and 29 deletions

View file

@ -0,0 +1,60 @@
// The Antville Project
// http://code.google.com/p/antville
//
// Copyright 2007-2011 by Tobi Schäfer.
//
// Copyright 20012007 Robert Gaggl, Hannes Wallnöfer, Tobi Schäfer,
// Matthias & Michael Platzer, Christoph Lincke.
//
// Licensed under the Apache License, Version 2.0 (the ``License'');
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an ``AS IS'' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// $Revision$
// $Author$
// $Date$
// $URL$
/**
* @fileoverview Defines the Antville reCAPTCHA Feature.
* @see http://www.google.com/recaptcha
*/
registerExtra("recaptcha", new function() {
var key = getProperty("recaptcha.key");
return {
_macro: function() {
if (key && !session.user) {
renderSkin("recaptcha", {id: getProperty("recaptcha.id")});
}
return;
},
verify: function(data) {
var http = new helma.Http;
http.setTimeout(200);
http.setReadTimeout(300);
http.setMethod("POST");
http.setContent({
privatekey: key,
remoteip: req.data.http_remotehost,
challenge: data.recaptcha_challenge_field,
response: data.recaptcha_response_field
});
var request = http.getUrl("http://www.google.com/recaptcha/api/verify");
if (request.code === 200 && !request.content.startsWith("true")) {
throw Error(gettext("Please enter the correct words in the CAPTCHA box."));
}
return;
}
}
});

View file

@ -0,0 +1,14 @@
<script type="text/javascript">
var RecaptchaOptions = {
theme: 'default',
lang: '<% site.locale %>'
};
</script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=<% param.id %>">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=<% param.id %>"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge">
</noscript>