From db0d62ed4ad93995c9a5df4c46a3e06eee8c37c1 Mon Sep 17 00:00:00 2001 From: devjin Date: Wed, 12 Oct 2011 07:45:10 +0000 Subject: [PATCH] issue 423 fixed sign up capcha git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9607 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- addons/captcha/captcha.addon.php | 77 ++++++++++++++++--- addons/captcha/inline_captcha.js | 17 ++++ common/lang/lang.xml | 12 +++ modules/member/skins/default/signup_form.html | 6 ++ 4 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 addons/captcha/inline_captcha.js diff --git a/addons/captcha/captcha.addon.php b/addons/captcha/captcha.addon.php index 96312e4ce..9c433e093 100644 --- a/addons/captcha/captcha.addon.php +++ b/addons/captcha/captcha.addon.php @@ -33,6 +33,8 @@ if($this->addon_info->target != 'all' && Context::get('is_logged')) return false; if($_SESSION['captcha_authed']) return false; + $type = Context::get('captchaType'); + $target_acts = array('procBoardInsertDocument','procBoardInsertComment','procIssuetrackerInsertIssue','procIssuetrackerInsertHistory','procTextyleInsertComment'); if($this->addon_info->apply_find_account=='apply') $target_acts[] = 'procMemberFindAccount'; if($this->addon_info->apply_resend_auth_mail=='apply') $target_acts[] = 'procMemberResendAuthMail'; @@ -40,11 +42,15 @@ if(Context::getRequestMethod()!='XMLRPC' && Context::getRequestMethod()!=='JSON') { - Context::addHtmlHeader(''); - Context::loadFile(array('./addons/captcha/captcha.js', 'body', '', null), true); + if($type == 'inline') { + $this->compareCaptcha(); + } else { + Context::addHtmlHeader(''); + Context::loadFile(array('./addons/captcha/captcha.js', 'body', '', null), true); + } } - // compare session when calling actions such as writing a post or a comment on the board/issue tracker module + // compare session when calling actions such as writing a post or a comment on the board/issue tracker module if(!$_SESSION['captcha_authed'] && in_array(Context::get('act'), $target_acts)) { Context::loadLang('./addons/captcha/lang'); $ModuleHandler->error = "captcha_denied"; @@ -53,6 +59,17 @@ return true; } + function createKeyword() + { + $type = Context::get('captchaType'); + if ($type == 'inline' && $_SESSION['captcha_keyword']) return; + + $arr = range('A','Y'); + shuffle($arr); + $arr = array_slice($arr,0,6); + $_SESSION['captcha_keyword'] = join('', $arr); + } + function before_module_init_setCaptchaSession() { if($_SESSION['captcha_authed']) return false; @@ -61,10 +78,7 @@ Context::loadLang(_XE_PATH_.'addons/captcha/lang'); // Generate keywords - $arr = range('A','Y'); - shuffle($arr); - $arr = array_slice($arr,0,6); - $_SESSION['captcha_keyword'] = join('', $arr); + $this->createKeyword(); $target = Context::getLang('target_captcha'); header("Content-Type: text/xml; charset=UTF-8"); @@ -87,6 +101,7 @@ function before_module_init_captchaImage() { if($_SESSION['captcha_authed']) return false; + if(Context::get('renew')) $this->createKeyword(); $keyword = $_SESSION['captcha_keyword']; $im = $this->createCaptchaImage($keyword); @@ -224,12 +239,23 @@ return $data; } + function compareCaptcha() + { + if($_SESSION['captcha_authed']) return true; + + if(strtoupper($_SESSION['captcha_keyword']) == strtoupper(Context::get('secret_text'))) { + $_SESSION['captcha_authed'] = true; + return true; + } + + unset($_SESSION['captcha_authed']); + + return false; + } + function before_module_init_captchaCompare() { - if($_SESSION['captcha_authed']) return false; - - if(strtoupper($_SESSION['captcha_keyword']) == strtoupper(Context::get('secret_text'))) $_SESSION['captcha_authed'] = true; - else unset($_SESSION['captcha_authed']); + if(!$this->compareCaptcha()) return false; header("Content-Type: text/xml; charset=UTF-8"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); @@ -242,10 +268,39 @@ Context::close(); exit(); } + + function inlineDisplay() + { + unset($_SESSION['captcha_authed']); + $this->createKeyword(); + + $swfURL = getUrl().'addons/captcha/swf/play.swf'; + Context::unloadFile('./addons/captcha/captcha.js'); + Context::loadFile(array('./addons/captcha/inline_captcha.js','body')); + + global $lang; +?> +CAPTCHA + + + + + + + + + + +
+ + +setInfo($addon_info); + Context::set('oCaptcha', &$GLOBALS['__AddonCaptcha__']); } $oAddonCaptcha = &$GLOBALS['__AddonCaptcha__']; diff --git a/addons/captcha/inline_captcha.js b/addons/captcha/inline_captcha.js new file mode 100644 index 000000000..26ff64a1b --- /dev/null +++ b/addons/captcha/inline_captcha.js @@ -0,0 +1,17 @@ +jQuery(function($){ + $('button.captchaPlay') + .click(function(){ + var swf = document['captcha_audio'] || window['captcha_audio']; + var audio = current_url.setQuery('captcha_action','captchaAudio').setQuery('rand', (new Date).getTime()); + + if(swf.length > 1) swf = swf[0]; + + $('input[type=text]#secret_text').focus(); + swf.setSoundTarget(audio,'1'); + }); + + $('button.captchaReload') + .click(function(){ + $("#captcha_image").attr("src", current_url.setQuery('captcha_action','captchaImage').setQuery('rand', (new Date).getTime()).setQuery('renew',1)); + }); +}); diff --git a/common/lang/lang.xml b/common/lang/lang.xml index a82f39e97..512f335c9 100644 --- a/common/lang/lang.xml +++ b/common/lang/lang.xml @@ -3796,4 +3796,16 @@ Bitte melden Sie sich dem Administrator des Moduls!]]> + + + + + + + + + + + + diff --git a/modules/member/skins/default/signup_form.html b/modules/member/skins/default/signup_form.html index 3b69f20c8..7f78ec2d9 100644 --- a/modules/member/skins/default/signup_form.html +++ b/modules/member/skins/default/signup_form.html @@ -58,6 +58,12 @@

+
  • +

    {$lang->captcha}

    +

    + {$oCaptcha->inlineDisplay()} +

    +