Changeset 1917973
- Timestamp:
- 08/01/2018 05:54:10 AM (8 years ago)
- Location:
- vaptcha/trunk
- Files:
-
- 10 edited
-
VaptchaPlugin.php (modified) (11 diffs)
-
js/init-vaptcha.js (modified) (1 diff)
-
languages/vaptcha-en_US.mo (modified) (previous)
-
languages/vaptcha-en_US.po (modified) (2 diffs)
-
lib/Vaptcha.class.php (modified) (2 diffs)
-
lib/config.php (modified) (1 diff)
-
options.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
-
uninstall.php (modified) (1 diff)
-
vaptcha.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
vaptcha/trunk/VaptchaPlugin.php
r1788540 r1917973 21 21 private function get_captcha($form, $btn) { 22 22 $script = plugins_url( 'js/init-vaptcha.js', __FILE__ ); 23 $vid = get_option('vaptcha_options')['vaptcha_vid']; 23 24 $lang = get_option('vaptcha_options')['vaptcha_lang']; 24 25 $ai = get_option('vaptcha_options')['vaptcha_ai']; … … 29 30 $https = get_option('vaptcha_options')['https']; 30 31 $type = get_option('vaptcha_options')['type']; 32 $height = $height ? $height : '36px'; 33 $options = json_encode(Array( 34 "vid" => $vid, 35 "type" => $type, 36 "lang" => $lang, 37 "style" => $style, 38 "https" => $https, 39 "color" => $color, 40 )); 31 41 return <<<HTML 32 42 <style> 33 #wpVaptchaConatiner{43 .vaptcha-container{ 34 44 height: $height; 35 45 width: $width; … … 69 79 } 70 80 </style> 71 <div id="wpVaptchaConatiner">81 <div class="vaptcha-container" data-config='$options'> 72 82 <div class="vaptcha-init-main"> 73 83 <div class="vaptcha-init-loading"> … … 77 87 </div> 78 88 </div> 79 <input type="hidden" name="vaptcha_challenge"/>80 <input type="hidden" name="vaptcha_token"/>81 <script type="text/javascript" src="https://cdn.vaptcha.com/v.js"></script>82 89 <script type="text/javascript" src="$script"></script> 83 <script>84 (function(){85 var vp = document.getElementById('wpVaptchaConatiner');86 var form = document.getElementById('$form');87 form.insertBefore(vp, form.getElementsByClassName('$btn')[0]);88 initVaptcha({89 container: vp,90 type: '$type',91 lang: '$lang',92 style: '$style',93 https: $https,94 color: '$color',95 ai: $ai,96 outage: '/wp-json/vaptcha/downtime',97 success: function (token, challenge) {98 var inputs = form.getElementsByTagName('input');99 inputs['vaptcha_challenge'].value = challenge;100 inputs['vaptcha_token'].value = token;101 inputs['is_success'] && (inputs['is_success'].value = 'yes');102 }103 });104 })()105 </script>106 90 HTML; 107 91 } … … 113 97 if($this->options['vaptcha_comment'] == 0) return ; 114 98 echo $this->get_captcha('commentform', 'form-submit'); 99 echo <<<HTML 100 <script> 101 var btn = document.getElementsByClassName('vaptcha-container')[0] 102 var form = document.getElementById('commentform') 103 form.insertBefore(btn, document.getElementsByClassName('form-submit')[0]) 104 </script> 105 HTML; 115 106 } 116 107 … … 120 111 $token = $_POST['vaptcha_token']; 121 112 if (!$token || !$this->vaptcha->validate($challenge, $token)) { 122 wp_die(__( "人机验证未通过"));113 wp_die(__('人机验证未通过', 'vaptcha')); 123 114 } 124 115 return $comment_data; … … 138 129 $token = $_POST['vaptcha_token']; 139 130 if (!$token || !$this->vaptcha->validate($challenge, $token)) { 140 return new WP_Error('broke', __( "人机验证未通过"));131 return new WP_Error('broke', __('人机验证未通过', 'vaptcha')); 141 132 } 142 133 return $user; … … 153 144 $token = $_POST['vaptcha_token']; 154 145 if (!$token || !$this->vaptcha->validate($challenge, $token)) { 155 $errors->add('captcha_wrong', "<strong>ERROR</strong>:".__('人机验证未通过' ));146 $errors->add('captcha_wrong', "<strong>ERROR</strong>:".__('人机验证未通过', 'vaptcha')); 156 147 } 157 148 return $errors; … … 225 216 return json_decode($this->vaptcha->downTime($_GET['data'])); 226 217 } 218 219 function captcha_in_woocommerce() { 220 echo $this->get_captcha('woocommerce-form-register', 'submit'); 221 } 222 223 function captcha_validate_woocommerce($errors) { 224 $token = $_POST['vaptcha_token']; 225 if (!$token || !$this->vaptcha->validate($challenge, $token)) { 226 $errors->add('captcha_wrong', __('人机验证未通过', 'vaptcha')); 227 } 228 return $errors; 229 } 230 231 function captcha_validate_woocommerce_allow($data) { 232 $token = $_POST['vaptcha_token']; 233 if (!$token || !$this->vaptcha->validate($challenge, $token)) { 234 return new WP_Error('captcha_wrong', __('人机验证未通过', 'vaptcha')); 235 } 236 return $data; 237 } 227 238 228 239 function init_add_actions() { … … 233 244 add_action('admin_init', array($this, 'vaptcha_settings_init')); 234 245 add_action('admin_menu', array($this, 'vaptcha_options_page')); 246 247 add_action('woocommerce_login_form', array($this, 'captcha_in_woocommerce')); 248 add_action('woocommerce_register_form', array($this, 'captcha_in_woocommerce')); 249 add_action('woocommerce_lostpassword_form', array($this, 'captcha_in_woocommerce')); 235 250 236 251 //api … … 249 264 add_filter('wp_authenticate_user', array($this, 'captcha_validate_login'),100,1); 250 265 add_filter('registration_errors', array($this, 'captcha_validate_register'),100,1); 266 267 // add_filter('woocommerce_process_login_errors', array($this, 'captcha_validate_woocommerce'),100,1); 268 add_filter('woocommerce_process_registration_errors', array($this, 'captcha_validate_woocommerce'),100,1); 269 add_filter('lostpassword_post', array($this, 'captcha_validate_woocommerce'),100,1); 251 270 } 252 271 -
vaptcha/trunk/js/init-vaptcha.js
r1788540 r1917973 1 var initVaptcha = function (options) { 2 var xmlHttp; 3 function createxmlHttpRequest() { 4 if (window.ActiveXObject) { 5 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 6 } else if (window.XMLHttpRequest) { 7 xmlHttp = new XMLHttpRequest(); 1 (function(){ 2 function loadVaptcha() { 3 var script = document.getElementById('vaptcha_v_js'); 4 if (script && window.vaptcha && script.loaded) { 5 } else { 6 script = document.createElement('script'); 7 protocol = 'https'; //options.https ? 'https' : 'http'; 8 script.src = protocol + '://cdn.vaptcha.com/v2.js'; 9 script.id = 'vaptcha_v_js'; 10 script.async = true 11 script.onload = script.onreadystatechange = function () { 12 if (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') { 13 script.loaded = true; 14 script.onload = script.onreadystatechange = null; 15 } 16 }; 17 document.getElementsByTagName("head")[0].appendChild(script); 8 18 } 9 19 } 10 11 createxmlHttpRequest(); 12 xmlHttp.open("GET", "/wp-json/vaptcha/getchallenge?t=" + Date.now()); 13 xmlHttp.send(null); 14 xmlHttp.onreadystatechange = function (result) { 15 if ((xmlHttp.readyState === 4) && (xmlHttp.status === 200)) { 16 var data = JSON.parse(xmlHttp.responseText); 17 options.vid = data.vid; 18 options.challenge = data.challenge; 19 window.vaptcha(options, function (obj) { 20 vaptcha_obj = obj; 21 //执行初始化 22 vaptcha_obj.init(); 23 }); 24 } 25 } 26 } 20 loadVaptcha() 21 }()) -
vaptcha/trunk/languages/vaptcha-en_US.po
r1788540 r1917973 2 2 msgstr "" 3 3 "Project-Id-Version: VAPTCHA\n" 4 "POT-Creation-Date: 201 7-12-18 14:42+0800\n"5 "PO-Revision-Date: 201 7-12-18 14:42+0800\n"4 "POT-Creation-Date: 2018-07-24 14:35+0800\n" 5 "PO-Revision-Date: 2018-07-24 14:38+0800\n" 6 6 "Last-Translator: \n" 7 7 "Language-Team: \n" … … 21 21 "X-Poedit-SearchPathExcluded-0: *.js\n" 22 22 23 #: VaptchaPlugin.php:122 VaptchaPlugin.php:140 VaptchaPlugin.php:155 23 #: VaptchaPlugin.php:130 VaptchaPlugin.php:148 VaptchaPlugin.php:163 24 #: VaptchaPlugin.php:244 VaptchaPlugin.php:252 24 25 msgid "人机验证未通过" 25 msgstr " man-machine validation failed"26 msgstr "man-machine validation failed" 26 27 27 28 #: options.php:14 -
vaptcha/trunk/lib/Vaptcha.class.php
r1788540 r1917973 81 81 public function validate($challenge, $token, $sceneId = "") 82 82 { 83 if ($this->isDown || !$challenge)83 if ($this->isDown) 84 84 return $this->downTimeValidate($token); 85 85 else … … 172 172 private function normalValidate($challenge, $token, $sceneId) 173 173 { 174 if (!$token || !$challenge || $token != md5($this->key.'vaptcha'.$challenge))174 if (!$token) 175 175 return false; 176 $url = $this->config['API_URL'].$this->config['VALIDATE_URL']; 177 $now = $this->getCurrentTime(); 178 $query = "id=$this->vid&scene=$sceneId&token=$token&time=$now&version=".$this->config['VERSION'].'&sdklang='.$this->config['SDK_LANG']; 179 $signature = $this->HMACSHA1($this->key, $query); 180 $response = self::postValidate($url, array( 176 $url = $this->config[API_URL].$this->config[VALIDATE_URL]; 177 $now = $this->getCurrentTime(); 178 // $query = "id=$this->vid&scene=$sceneId&secretkey=$this->key&token=$token&ip=$_SERVER[REMOTE_ADDR]"; 179 $response = json_decode(self::postValidate($url, array( 181 180 'id' => $this->vid, 182 181 'scene' => $sceneId, 183 'token' => $token, 184 'time' => $now, 185 'version' => $this->config['VERSION'], 186 'sdklang' => $this->config['SDK_LANG'], 187 'signature' => $signature 188 )); 189 return 'success' == $response; 182 'secretkey' => $this->key, 183 'token' => $token, 184 'ip' => $_SERVER[REMOTE_ADDR] 185 ))); 186 return $response->success == 1; 190 187 } 191 188 -
vaptcha/trunk/lib/config.php
r1788540 r1917973 11 11 'VERSION' => '1.1.0', 12 12 'SDK_LANG' => 'php', 13 'API_URL' => 'http://api.vaptcha.com ',13 'API_URL' => 'http://api.vaptcha.com/v2', 14 14 'GET_CHALLENGE_URL' => '/challenge', 15 15 'VALIDATE_URL' => '/validate', -
vaptcha/trunk/options.php
r1788540 r1917973 59 59 </th> 60 60 </tr> 61 < tr>61 <!-- <tr> 62 62 <th><label for="tag_base"><?php _e('智能检测', 'vaptcha') ?></label></th> 63 63 <td> … … 68 68 </td> 69 69 <td> <?php _e('如果开启,高风险操作或者客户端在验证时需要进行手势验证,无风险客户端则可以一键通过验证,大幅提升用户体验', 'vaptcha') ?> </td> 70 </tr> 70 </tr> --> 71 71 <tr> 72 72 <th><label for="tag_base"><?php _e('HTTPS', 'vaptcha') ?></label></th> -
vaptcha/trunk/readme.txt
r1788542 r1917973 61 61 * Add the button style options, you can choose dark, light color. 62 62 * Update VAPTCHA SDK. 63 64 = 1.2.0 65 * Update VAPTCHA v2.0 -
vaptcha/trunk/uninstall.php
r1762649 r1917973 20 20 * 21 21 * @link https://www.vaptcha.com 22 * @since 1. 0.022 * @since 1.2.0 23 23 * 24 24 * @package vaptcha -
vaptcha/trunk/vaptcha.php
r1788540 r1917973 4 4 Plugin URI: https://www.vaptcha.com 5 5 Description: VAPTCHA是”Variation Analysis - based Public Turing Test to Tell Computers and Humans Apart ”的简称,也叫手势验证。一种通过用户鼠标手势即可完成人机验证的图灵测试程序。VAPTCHA更加简单和安全,是目前传统验证码的最佳替代方案。VAPTCHA不仅大幅节省了用户在使用互联网服务时在人机验证上面的耗时,平均通过时间不超过1秒,同时也是目前世界上最不可能被破解的验证系统。 6 Version: 1. 1.06 Version: 1.2.0 7 7 Author: vaptcha 8 8 Text Domain: vaptcha
Note: See TracChangeset
for help on using the changeset viewer.