Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion action.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,28 @@ function register(&$controller) {
array('editform' => false, 'oldhook' => false)
);
}
if($this->getConf('loginprotect')) {
$controller->register_hook(
'HTML_LOGINFORM_OUTPUT',
'BEFORE',
$this,
'handle_login_form',
array()
);
}
}

/**
* Will intercept the 'save' action and check for CAPTCHA first.
*/
function handle_act_preprocess(&$event, $param) {
$act = $this->_act_clean($event->data);

if($this->getConf('loginprotect')) {
$this->handle_login();
return;
}

if(!('save' == $act || ($this->getConf('regprotect') &&
'register' == $act &&
$_POST['save']))
Expand Down Expand Up @@ -97,6 +112,7 @@ function handle_act_preprocess(&$event, $param) {

/**
* Create the additional fields for the edit form
* @author Myron Turner <[email protected]>
*/
function handle_editform_output(&$event, $param) {
// check if source view -> no captcha needed
Expand Down Expand Up @@ -125,7 +141,38 @@ function handle_editform_output(&$event, $param) {
$event->data->insertElement($pos++, $out);
}
}

/**
* Insert captcha into login form if loginprotect is true
* @url parameter: chk=captcha_check, identifies login mode
* @author Myron Turner <[email protected]>
*/
function handle_login_form(&$event, $param) {
$pos = $event->data->findElementByAttribute('type', 'submit');
$helper = plugin_load('helper', 'captcha');
$out = $helper->getHTML();
$event->data->_hidden['chk'] = 'captcha_check';
$event->data->insertElement($pos+1, $out);
}

/**
* Redirect with additional parameters if captcha fails and
* output 'testfailed' message on re-load
*
* @url_param: do=logout => to force logout
*
* @author Myron Turner <[email protected]>
*/
function handle_login() {
if(isset($_REQUEST['chk'])) {
$helper = $this->loadHelper('captcha', true);
if(!$helper->check()) {
msg($helper->getLang('testfailed'), -1);
$url = wl('',array('do'=>'logout'), true, '&') ;
send_redirect($url);
exit();
}
}
}
/**
* Pre-Sanitize the action command
*
Expand Down
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
$conf['height'] = 22;
$conf['question'] = 'What\'s the answer to life, the universe and everything?';
$conf['answer'] = '42';
$conf['loginprotect'] = 0;
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
$meta['height'] = array('numeric', '_pattern' => '/[0-9]+/');
$meta['question'] = array('string');
$meta['answer'] = array('string');
$meta['loginprotect'] = array('onoff');
1 change: 1 addition & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
$lang['height'] = "Height of the CAPTCHA image (pixel)";
$lang['question'] = "Question for fixed question mode";
$lang['answer'] = "Answer for fixed question mode";
$lang['loginprotect'] = "Protect login form";
2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
base captcha
author Andreas Gohr
email [email protected]
date 2014-01-05
date 2014-12-28
name CAPTCHA Plugin
desc Use a CAPTCHA challenge to protect DokuWiki against automated spam
url http://www.dokuwiki.org/plugin:captcha
Expand Down