Plugin Directory

Changeset 2513195


Ignore:
Timestamp:
04/12/2021 10:06:02 AM (5 years ago)
Author:
vaptcha
Message:

修复注册流程bug,修改插件设置页提示文字

Location:
vaptcha-sms/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • vaptcha-sms/trunk/VaptchaSmsPlugin.php

    r2511966 r2513195  
    3838     * 加载vaptcha
    3939     */
    40     private function get_captcha($form, $btn,$type)
     40    private function get_captcha($form, $btn, $type)
    4141    {
    4242        $loading = plugins_url('images/vaptcha-loading.gif', __FILE__);
     
    115115    //    选择国别码
    116116
    117     function select_code_box(){
     117    function select_code_box()
     118    {
    118119        $dropdown = plugins_url('images/dropdown.png', __FILE__);
    119120
     
    177178                            <input type="text" id="country_code" class="form-control" style="border: none;outline: none!important;" value="86" name="country_code">
    178179                            <button id="btn-down" type="button" style="background: none;border: none;outline: none;padding: 0 3px">
    179                                 <img id="dropdown-icon" src="' .$dropdown.'" style="width: 10px;"/>
     180                                <img id="dropdown-icon" src="' . $dropdown . '" style="width: 10px;"/>
    180181                            </button>
    181182                        </div>
     
    242243        //判断是否在登陆时出现vaptcha验证,为off时不验证
    243244        if ($this->options['button_no_secret'] == 'off') return;
    244         else{
     245        else {
    245246            $ajaxUrl = admin_url('admin-ajax.php');
    246             if ($this->options['button_international'] == 'off'){
     247            if ($this->options['button_international'] == 'off') {
    247248                echo '<p id="phone-verify-fields">
    248249                <label for="user_phone">手机号</label>
     
    250251            </p>
    251252            ';
    252             }else{
     253            } else {
    253254                echo $this->select_code_box();
    254255            };
     
    278279                    <input type="hidden" name="reset_way" id="reset_way" value="phone">
    279280            </p>';
    280             echo $this->get_captcha('loginform', 'submit','click');
     281            echo $this->get_captcha('loginform', 'submit', 'click');
    281282            echo <<<HTML
    282283            <button type="button" id="submit_form_button" class="button" style="height: 32px;float: right;background: #2271b1;color: white;">免密登录</button>
    283             <button type="button" id="sms_login_button" class="button" style="display: none;height: 32px;float: right;background: #2271b1;color: white;">登录</button>
     284            <button type="button" id="sms_login_button" class="button" style="display: none;padding: 0 15px;height: 32px;float: right;background: #2271b1;color: white;">登录</button>
    284285HTML;
    285286        }
     
    302303            //验证账号密码是否输入的是手机号
    303304            return $error;
    304         }else{
     305        } else {
    305306            //通过手机号查找用户
    306307            $args = array(
     
    309310            );
    310311            $phoneFindUser = get_users($args);
    311             if ( !empty($phoneFindUser) ) {
     312            if (!empty($phoneFindUser)) {
    312313                $phoneFindUser = $phoneFindUser[0];
    313314            }
    314315            //通过用户名和手机号都未找到用户
    315             if ( !($phoneFindUser instanceof WP_User)) {
     316            if (!($phoneFindUser instanceof WP_User)) {
    316317                return new WP_Error('captcha_wrong', __('该手机号未绑定用户。', 'vaptcha'));
    317318            }
     
    329330     * @return string
    330331     */
    331     function yang_allow_phone_login($username, $raw_username, $strict) {
    332         if( !empty($raw_username) && preg_match("/^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/", $raw_username) ){
     332    function yang_allow_phone_login($username, $raw_username, $strict)
     333    {
     334        if (!empty($raw_username) && preg_match("/^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/", $raw_username)) {
    333335            global $wpdb;
    334336            $user_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM $wpdb->usermeta jw WHERE jw.meta_key='%s' AND jw.meta_value='%s'", 'phone', $raw_username));
    335             if (empty($user_id)){
     337            if (empty($user_id)) {
    336338                wp_die(__('ERROR: There is no user registered with that phone number.'), '用户名不正确');
    337             }else{
    338                 if( function_exists('get_user_by') ){
    339                     include_once(ABSPATH.'wp-includes/pluggable.php');
     339            } else {
     340                if (function_exists('get_user_by')) {
     341                    include_once(ABSPATH . 'wp-includes/pluggable.php');
    340342                }
    341343                $user = get_user_by('id', $user_id);
    342344                return $user->user_login;
    343345            }
    344         }else{
     346        } else {
    345347            return $username;
    346348        }
     
    348350
    349351
    350 
    351352    /**
    352353     * 修改注册表单
     
    354355    function captcha_in_register_form()
    355356    {
    356         if ($this->options['button_international'] == 'off'){
     357        if ($this->options['button_international'] == 'off') {
    357358            echo '<p>
    358359                <label for="user_phone">手机号</label>
    359360                <input type="text" name="user_phone" id="user_phone" class="input" size="20" autocapitalize="off" />
    360361            </p>';
    361         }else{
     362        } else {
    362363            echo $this->select_code_box();
    363364        }
    364365
    365         echo '<p>
     366        echo '
     367            <style>
     368            #wp-submit{
     369            display: none;
     370            }
     371            </style>
     372            <p>
    366373                <p><label for="">短信验证码</label></p>
    367374                <input type="text" name="register_sms_code" id="register_sms_code" style="width: 150px;" autocapitalize="off" />
    368375                <button type="button" id="get_sms_code" class="button" style="height: 40px;width: 110px">发送验证码</button>
    369376            </p>
     377            <p><button type="button" id="submit-btn" class="button" style="height: 32px;padding: 0 15px;float: right;background: #2271b1;color: white;margin-top: 30px">注册</button></p>
    370378';
    371         echo $this->get_captcha('registerform', 'submit','invisible');
     379        echo $this->get_captcha('registerform', 'submit', 'invisible');
    372380    }
    373381
     
    379387    function captcha_validate_register($errors)
    380388    {
    381         $smsid = get_option('vaptcha_options')['vaptcha_smsid'];
    382         $smskey = get_option('vaptcha_options')['vaptcha_smskey'];
    383         $phone = sanitize_text_field($_POST['user_phone']);
    384         $vcode = sanitize_text_field($_POST['register_sms_code']);
    385 
    386         if(!$phone){
    387             $errors->add('captcha_wrong', "<strong>ERROR</strong>:" . __('请输入手机号。', 'vaptcha'));
    388         }else{
    389 
    390             $args = array(
    391                 'meta_key' => 'phone',
    392                 'meta_value' => $phone,
    393             );
    394             $phoneFindUser = get_users($args);
    395 
    396             if(!!$phoneFindUser){
    397                 $errors->add('captcha_wrong', "<strong>ERROR</strong>:" . __('该手机号已绑定其他用户。', 'vaptcha'));
    398             }else{
    399                 $res = $this->vaptcha->validateSmsCode($smsid,$smskey,$phone,$vcode);
    400                 if (!empty($res)) {
    401                     $errors->add('captcha_wrong', "<strong>ERROR</strong>:" . __($res, 'vaptcha'));
    402                 }
    403             }
    404         }
     389//        $smsid = get_option('vaptcha_options')['vaptcha_smsid'];
     390//        $smskey = get_option('vaptcha_options')['vaptcha_smskey'];
     391//        $phone = sanitize_text_field($_POST['user_phone']);
     392//        $vcode = sanitize_text_field($_POST['register_sms_code']);
     393//
     394//        if (!$phone) {
     395//            $errors->add('captcha_wrong', "<strong>ERROR</strong>:" . __('请输入手机号。', 'vaptcha'));
     396//        } else {
     397//
     398//            $args = array(
     399//                'meta_key' => 'phone',
     400//                'meta_value' => $phone,
     401//            );
     402//            $phoneFindUser = get_users($args);
     403//
     404//            if (!!$phoneFindUser) {
     405//                $errors->add('captcha_wrong', "<strong>ERROR</strong>:" . __('该手机号已绑定其他用户。', 'vaptcha'));
     406//            } else {
     407//                $res = $this->vaptcha->validateSmsCode($smsid, $smskey, $phone, $vcode);
     408//                if ($res == 601) {
     409//                    $errors->add('captcha_wrong', "<strong>ERROR</strong>:" . __('短信验证码错误。', 'vaptcha'));
     410//                }
     411//            }
     412//        }
    405413        return $errors;
    406414    }
     
    410418     * 保存用户手机号码
    411419     */
    412     function user_register_prestige($user_id){
     420    function user_register_prestige($user_id)
     421    {
    413422        $user_phone = sanitize_text_field($_POST['user_phone']);
    414         update_user_meta($user_id,'phone',$user_phone);
     423        update_user_meta($user_id, 'phone', $user_phone);
    415424    }
    416425
     
    447456        $userid = $user->ID;
    448457        $user_phone = $validated['vaptcha_phone'];
    449         update_user_meta($userid,'phone',$user_phone);
     458        update_user_meta($userid, 'phone', $user_phone);
    450459        return $validated;
    451460    }
     
    465474
    466475
    467    /**
    468     * 退出设备菜单
    469     */
    470 
    471    function exit_device(){
    472 
    473        $this->removeDevice();
    474 
    475    }
     476    /**
     477     * 退出设备菜单
     478     */
     479
     480    function exit_device()
     481    {
     482
     483        $this->removeDevice();
     484
     485    }
    476486
    477487
     
    575585    public function load_sms_js()
    576586    {
    577         wp_register_script('vaptcha_sms_js', plugins_url('js/sms.js', __FILE__),array('jquery'), '1.1', true);
     587        wp_register_script('vaptcha_sms_js', plugins_url('js/sms.js', __FILE__), array('jquery'), '1.1', true);
    578588        wp_enqueue_script('vaptcha_sms_js');
    579589
    580         wp_register_script('vaptcha_v3_js', 'https://v.vaptcha.com/v3.js',array('jquery'), '1.1', true);
     590        wp_register_script('vaptcha_v3_js', 'https://v.vaptcha.com/v3.js', array('jquery'), '1.1', true);
    581591        wp_enqueue_script('vaptcha_v3_js');
     592    }
     593
     594    /**
     595     * 验证注册表单
     596     */
     597
     598    public function validateRegister()
     599    {
     600        $smsid = get_option('vaptcha_options')['vaptcha_smsid'];
     601        $smskey = get_option('vaptcha_options')['vaptcha_smskey'];
     602        $username = sanitize_text_field($_POST['username']);
     603        $email = sanitize_text_field($_POST['email']);
     604        $phone = sanitize_text_field($_POST['phone']);
     605        $smscode = sanitize_text_field($_POST['smscode']);
     606
     607        $args = array(
     608            'meta_key' => 'phone',
     609            'meta_value' => $phone,
     610        );
     611        $phoneFindUser = get_users($args);
     612        $exists = email_exists($email);//检查邮箱是否存在
     613        $user = username_exists($username);//检查用户名是否存在
     614        if ($user) {
     615            $name = '该用户名已被注册。';
     616        }
     617        if ($exists) {
     618            $mail = '该邮箱地址已被注册。';
     619        }
     620        if (!!$phoneFindUser) {
     621            $phoneNumber = '该手机号已绑定其他用户。';
     622        } else {
     623            $res = $this->vaptcha->validateSmsCode($smsid, $smskey, $phone, $smscode);
     624            if ($res == 601) {
     625                $code = '短信验证码错误';
     626            }
     627        }
     628        if ($name === null && $mail === null && $phoneNumber=== null && $code === null){
     629            wp_send_json_success();
     630        }else{
     631            wp_send_json_error(array(
     632                'name' => $name,
     633                'email' => $mail,
     634                'phone' => $phoneNumber,
     635                'smscode' => $code
     636            ));
     637        }
     638
    582639    }
    583640
     
    591648        $url = 'https://sms.vaptcha.com/smsid?id=' . $vid . '&key=' . $key;
    592649        $response = wp_remote_get($url);
    593         $data =  json_decode($response['body']);
     650        $data = json_decode($response['body']);
    594651        wp_send_json_success($data);
    595652    }
     
    598655     * 发送手机短信验证码
    599656     */
    600     public function sendSmsCode(){
     657    public function sendSmsCode()
     658    {
    601659        $countrycode = sanitize_text_field($_POST['countrycode']);
    602660        $post_data = array(
     
    612670
    613671        $args = array(
    614             'body'        => $post_data,
    615             'timeout'     => '5',
     672            'body' => $post_data,
     673            'timeout' => '5',
    616674            'redirection' => '5',
    617675            'httpversion' => '1.0',
    618             'blocking'    => true,
    619             'headers'     => array("Content-type:application/json;charset='utf-8'",
     676            'blocking' => true,
     677            'headers' => array("Content-type:application/json;charset='utf-8'",
    620678                "Accept:application/json"),
    621679        );
    622680
    623         $response = wp_remote_post($url,$args);
    624         $data =  json_decode($response['body']);
     681        $response = wp_remote_post($url, $args);
     682        $data = json_decode($response['body']);
    625683        wp_send_json_success($data);
    626684    }
     
    630688     *
    631689     */
    632     public function getDeviceLogin(){
     690    public function getDeviceLogin()
     691    {
    633692        $phone = sanitize_text_field($_GET['phone']);
    634693        $token = sanitize_text_field($_GET['token']);
     
    639698        );
    640699        $phoneFindUser = get_users($args);
    641         if ( !empty($phoneFindUser) ) {
     700        if (!empty($phoneFindUser)) {
    642701            $phoneFindUser = $phoneFindUser[0];
    643702        }
    644703        //通过用户名和手机号都未找到用户
    645         if ( !($phoneFindUser instanceof WP_User)) {
    646             wp_send_json_error(array( 'code'=> 444 ,'msg'=> '该手机未绑定用户'));
     704        if (!($phoneFindUser instanceof WP_User)) {
     705            wp_send_json_error(array('code' => 444, 'msg' => '该手机未绑定用户'));
    647706        }
    648707        if (!$token || !$this->vaptcha->validate('', $token)) {
    649             wp_send_json_error(array( 'code'=> 444 ,'msg'=> '人机验证未通过'));
     708            wp_send_json_error(array('code' => 444, 'msg' => '人机验证未通过'));
    650709        }
    651710        $url = 'https://auth.vaptcha.com/api/v1/device?id=' . $phone . '&token=' . $token . '&renewal=1';
    652711        $response = wp_remote_get($url);
    653         $data =  json_decode($response['body']);
     712        $data = json_decode($response['body']);
    654713        wp_send_json_success($data);
    655714    }
     
    658717     * 添加登录设备
    659718     */
    660     public function addDevice(){
     719    public function addDevice()
     720    {
    661721        $smsid = get_option('vaptcha_options')['vaptcha_smsid'];
    662722        $smskey = get_option('vaptcha_options')['vaptcha_smskey'];
     
    670730        );
    671731        $phoneFindUser = get_users($args);
    672         if ( !empty($phoneFindUser) ) {
     732        if (!empty($phoneFindUser)) {
    673733            $phoneFindUser = $phoneFindUser[0];
    674734        }
    675735        //通过用户名和手机号都未找到用户
    676         if ( !($phoneFindUser instanceof WP_User)) {
    677             wp_send_json_error(array( 'code'=> 400 ,'msg'=> '该手机未绑定用户'));
    678         }
    679 
    680         $res = $this->vaptcha->validateSmsCode($smsid,$smskey,$phone,$vcode);
     736        if (!($phoneFindUser instanceof WP_User)) {
     737            wp_send_json_error(array('code' => 400, 'msg' => '该手机未绑定用户'));
     738        }
     739
     740        $res = $this->vaptcha->validateSmsCode($smsid, $smskey, $phone, $vcode);
    681741        if (!empty($res) && $res != 600) {
    682             wp_send_json_error(array( 'code'=> $res ,'msg'=> '短信验证未通过'));
     742            wp_send_json_error(array('code' => $res, 'msg' => '短信验证未通过'));
    683743        }
    684744        if (!$token || !$this->vaptcha->validate('', $token)) {
    685             wp_send_json_error(array( 'code'=> 400 ,'msg'=> '人机验证未通过'));
     745            wp_send_json_error(array('code' => 400, 'msg' => '人机验证未通过'));
    686746        }
    687747        $data = array(
     
    691751        $url = 'https://auth.vaptcha.com/api/v1/device';
    692752        $args = array(
    693             'method'      => 'PUT',
    694             'body'        => $data,
    695             'timeout'     => '5',
     753            'method' => 'PUT',
     754            'body' => $data,
     755            'timeout' => '5',
    696756            'redirection' => '5',
    697757            'httpversion' => '1.0',
    698             'blocking'    => true,
    699             'headers'     => array("Content-type:application/json;charset='utf-8'",
     758            'blocking' => true,
     759            'headers' => array("Content-type:application/json;charset='utf-8'",
    700760                "Accept:application/json"),
    701761        );
    702         $response = wp_remote_request($url,$args);
    703         $data =  json_decode($response['body']);
     762        $response = wp_remote_request($url, $args);
     763        $data = json_decode($response['body']);
    704764        wp_send_json_success($data);
    705765
     
    711771     * @return string|string[]
    712772     */
    713     function removeDevice(){
     773    function removeDevice()
     774    {
    714775        $user = get_currentuserinfo();
    715776        $userid = $user->ID;
     
    722783        $url = 'http://192.168.100.11:8080/api/v1/device';
    723784        $args = array(
    724             'method'      => 'DELETE',
    725             'body'        => json_encode($data),
    726             'timeout'     => '5',
     785            'method' => 'DELETE',
     786            'body' => json_encode($data),
     787            'timeout' => '5',
    727788            'redirection' => '5',
    728789            'httpversion' => '1.0',
    729             'blocking'    => true,
    730             'headers'     => array("Content-type:application/json;charset='utf-8'",
     790            'blocking' => true,
     791            'headers' => array("Content-type:application/json;charset='utf-8'",
    731792                "Accept:application/json"),
    732793        );
    733         $response = wp_remote_request($url,$args);
     794        $response = wp_remote_request($url, $args);
    734795//        $data =  json_decode($response['body']);
    735796//        wp_send_json_success($user);
     
    761822        //发送短信验证码
    762823        add_action('wp_ajax_nopriv_send_smscode', array($this, 'sendSmsCode'));
     824        add_action('wp_ajax_nopriv_submit_register', array($this, 'validateRegister'));
    763825        //设备登录
    764826        add_action('wp_ajax_nopriv_device_login', array($this, 'getDeviceLogin'));
     
    779841        add_filter('wp_logout', array($this, 'exit_device'), 101, 2);//注销钩子
    780842        add_filter('authenticate', array($this, 'captcha_validate_login'), 101, 3);//authenticate
    781         add_filter('sanitize_user',  array($this, 'yang_allow_phone_login'), 10, 3);
     843        add_filter('sanitize_user', array($this, 'yang_allow_phone_login'), 10, 3);
    782844        add_filter('registration_errors', array($this, 'captcha_validate_register'), 100, 1);
    783845        add_filter('woocommerce_process_registration_errors', array($this, 'captcha_validate_woocommerce'), 100, 1);
  • vaptcha-sms/trunk/js/sms.js

    r2511966 r2513195  
    1 jQuery(function ($){
     1jQuery(function ($) {
    22
    33    // 设置页获取短信id
     
    1717            },
    1818            success: function (response) {
    19                 if(response.data.code === 200){
     19                if (response.data.code === 200) {
    2020                    $('#vaptcha_smsid').val(response.data.data.smsid)
    2121                    $('#vaptcha_smskey').val(response.data.data.smskey)
    22                 }else {
     22                } else {
    2323                    alert(response.data.msg)
    2424                }
     
    2929
    3030    // 后台设置国别码
    31     $('#get_code').focus(function (){
    32     $('#code_menu').show()
    33     })
    34     $('#admin_phone').focus(function (){
     31    $('#get_code').focus(function () {
     32        $('#code_menu').show()
     33    })
     34    $('#admin_phone').focus(function () {
    3535        $('#code_menu').hide()
    3636    })
    3737
    38     $('#more_icon').click(function (){
    39         if($("#code_menu").is(":hidden")){
     38    $('#more_icon').click(function () {
     39        if ($("#code_menu").is(":hidden")) {
    4040            $('#code_menu').show()
    41         }else {
     41        } else {
    4242            $('#code_menu').hide()
    4343        }
     
    4545
    4646    //选择国别号下拉点击
    47     $("#code_menu").children("li").click(function(e) {
     47    $("#code_menu").children("li").click(function (e) {
    4848        $(this).addClass("active").siblings("li").removeClass("active");
    4949        var code = $(this).data('value');//点击时 当前li的值
     
    5353
    5454    // 加载vaptcha
    55     var operaticon='deviceLogin';
     55    var operaticon = 'deviceLogin';
    5656    var obj;
    5757    var ajaxUrl = document.getElementById('vaptcha-hidden-url').getAttribute('data-ajax-url')
     
    6363    console.log(type)
    6464    vaptcha({
    65         vid:  vid, // 验证单元id
     65        vid: vid, // 验证单元id
    6666        type: 'invisible', // 显示类型 隐藏式
    6767        scene: 0, // 场景值 默认0
     
    7272        vaptchaObj.listen('pass', function () {
    7373            // 验证成功进行后续操作
    74             if(operaticon === 'register'){
    75                 sendSmsCode(vaptchaObj.getToken(),'register')
    76             }
    77             if(operaticon === 'deviceLogin'){
     74            if (operaticon === 'register') {
     75                sendSmsCode(vaptchaObj.getToken(), 'register')
     76            }
     77            if (operaticon === 'deviceLogin') {
    7878                deviceLogin(vaptchaObj.getToken())
    7979            }
    80             if (operaticon === 'smsLogin'){
     80            if (operaticon === 'smsLogin') {
    8181                addDevice(vaptchaObj.getToken())
    8282            }
    83             if(operaticon === 'getSmsCode'){
    84                 sendSmsCode(vaptchaObj.getToken(),'login')
     83            if (operaticon === 'getSmsCode') {
     84                sendSmsCode(vaptchaObj.getToken(), 'login')
    8585            }
    8686            vaptchaObj.reset() //重置验证码
     
    9393
    9494    //发送验证码
    95     function sendSmsCode(token,key){
    96         $.ajax({
    97             type:'post',
     95    function sendSmsCode(token, key) {
     96        $.ajax({
     97            type: 'post',
    9898            url: ajaxUrl,
    9999            dataType: "json",
     
    107107                templateid: modelid,
    108108            },
    109             success:function (res){
    110                 if(res.data === 200){
    111                     key === 'register' ?  sendCountdown() : loginSendCountdown()
    112                 }else {
     109            success: function (res) {
     110                if (res.data === 200) {
     111                    key === 'register' ? sendCountdown() : loginSendCountdown()
     112                } else {
    113113                    alert(res.data)
    114114                }
     
    118118
    119119    //设备登录
    120     function deviceLogin(token){
    121         $.ajax({
    122             type:'get',
     120    function deviceLogin(token) {
     121        $.ajax({
     122            type: 'get',
    123123            url: ajaxUrl,
    124124            dataType: "json",
     
    128128                token: token,
    129129            },
    130             success:function(res){
    131                 if(res.data.code === 444){
    132                  //   $('#loginform').before('<p id="ajax-error-tips" class="message" style="border-left-color:red;display: none;">该手机号为未绑定已注册用户 <button id="to-bind-user" style="margin-top: -5px;" type="button" class="button button-primary">绑定用户</button><br> </p>');
     130            success: function (res) {
     131                if (res.data.code === 444) {
     132                    //   $('#loginform').before('<p id="ajax-error-tips" class="message" style="border-left-color:red;display: none;">该手机号为未绑定已注册用户 <button id="to-bind-user" style="margin-top: -5px;" type="button" class="button button-primary">绑定用户</button><br> </p>');
    133133                    alert(res.data.msg)
    134                 }else if(res.data.code === 200){
    135                         $('#loginform').submit()
    136                         }else if(res.data.code === 400){
    137                                 $('#sms-code').show()
    138                                 $('#submit_form_button').hide()
    139                                 $('#sms_login_button').show()
    140                                 operaticon = 'smsLogin'
    141                                 sendSmsCode(token,'login')
    142                               }
     134                } else if (res.data.code === 200) {
     135                    $('#loginform').submit()
     136                } else if (res.data.code === 400) {
     137                    $('#sms-code').show()
     138                    $('#submit_form_button').hide()
     139                    $('#sms_login_button').show()
     140                    operaticon = 'smsLogin'
     141                    sendSmsCode(token, 'login')
     142                }
    143143                // }
    144144            }
     
    146146    }
    147147
     148
     149    //验证注册表单
     150    $('#registerform').before('<p id="have_null" class="message" style="border-left-color:#e00101;display: none"><strong>错误:</strong>请将信息填写完整。</p>');
     151    $('#registerform').before('<p id="wrong_phone" class="message" style="border-left-color:#e00101;display: none"><strong>错误:</strong>请填写正确的手机号码。</p>');
     152    $('#registerform').before('<p id="wrong_email" class="message" style="border-left-color:#e00101;display: none"><strong>错误:</strong>请填写正确的手机号码。</p>');
     153    $('#registerform').before('<p id="exist_name" class="message" style="border-left-color:#e00101;margin-bottom: 0;padding: 5px 12px;display: none"><strong>错误:</strong>该用户名已被注册。</p>');
     154    $('#registerform').before('<p id="exist_email" class="message" style="border-left-color:#e00101;margin-bottom: 0;padding: 5px 12px;display: none"><strong>错误:</strong>该邮箱地址已被注册。</p>');
     155    $('#registerform').before('<p id="exist_phone" class="message" style="border-left-color:#e00101;margin-bottom: 0;padding: 5px 12px;display: none"><strong>错误:</strong>该手机号已绑定其他用户。</p>');
     156    $('#registerform').before('<p id="wrong_code" class="message" style="border-left-color:#e00101;margin-bottom: 0;padding: 5px 12px;display: none"><strong>错误:</strong>短信验证码错误。</p>');
     157
     158    $('#submit-btn').click(function () {
     159        var username = $('#user_login').val()
     160        var email = $('#user_email').val()
     161        var phone = $('#user_phone').val()
     162        var smscode = $('#register_sms_code').val()
     163        if (username == '' || smscode == '' || email == '' || phone == '') {
     164            $('#have_null').show()
     165            return
     166        } else {
     167            $('#have_null').hide()
     168        }
     169        var pattern = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
     170        strEmail = pattern.test(email);
     171        if (!strEmail) {
     172            $('#wrong_email').show()
     173            return
     174        } else {
     175            $('#wrong_email').hide()
     176        }
     177        if (phone === '' || !phone.match(/^1[3-9]\d{9}$/)) {
     178            $('#wrong_phone').show()
     179            return
     180        } else {
     181            $('#wrong_phone').hide()
     182        }
     183        if (smscode.length < 6 || smscode.length > 6) {
     184            $('#wrong_code').show()
     185            return;
     186        } else {
     187            $('#wrong_code').hide()
     188        }
     189        $.ajax({
     190            type: 'post',
     191            url: ajaxUrl,
     192            dataType: "json",
     193            data: {
     194                action: 'submit_register',
     195                username: username,
     196                email: email,
     197                phone: phone,
     198                smscode: smscode
     199            },
     200            success: function (res) {
     201                if (res.success === true) {
     202                    $('#registerform').submit()
     203                } else if (res.success === false) {
     204                    if (res.data.name != null) {
     205                        $('#exist_name').show()
     206                    } else {
     207                        $('#exist_name').hide()
     208                    }
     209                    if (res.data.email != null) {
     210                        $('#exist_email').show()
     211                    } else {
     212                        $('#exist_email').hide()
     213                    }
     214                    if (res.data.phone != null) {
     215                        $('#exist_phone').show()
     216                    } else {
     217                        $('#exist_phone').hide()
     218                    }
     219                    if (res.data.smscode != null) {
     220                        $('#wrong_code').show()
     221                    } else {
     222                        $('#wrong_code').hide()
     223                    }
     224                }
     225            }
     226        })
     227    })
     228
    148229    // 添加登录设备
    149     function addDevice(token){
    150         $.ajax({
    151             type:'post',
     230    function addDevice(token) {
     231        $.ajax({
     232            type: 'post',
    152233            url: ajaxUrl,
    153234            dataType: "json",
     
    160241                code: $('#sms_code').val()
    161242            },
    162             success:function (res){
    163                 if(res.data.code === 200){
     243            success: function (res) {
     244                if (res.data.code === 200) {
    164245                    $('#loginform').submit()
    165                 }else{
     246                } else {
    166247                    alert(res.data.msg)
    167248                }
     
    172253    // 重新获取验证码短信时间间隔
    173254    var waitTime = 60;
     255
    174256    function sendCountdown() {
    175257        if (waitTime > 0) {
     
    195277
    196278    //切换账号密码登录
    197     $('#name-or-email-login').click(function (){
     279    $('#name-or-email-login').click(function () {
    198280        $(this).hide();
    199281        $('#phone-login').show();
     
    204286        $('#user_login').parent().find('label').text('用户名、手机号或电子邮箱地址');
    205287        $('.user-pass-wrap').show();
    206         $('#user_pass').attr('disabled',false)
    207 
    208         $('#wp-submit').val('登录').css({"display":"block","margin-right":"0"});
     288        $('#user_pass').attr('disabled', false)
     289
     290        $('#wp-submit').val('登录').css({"display": "block", "margin-right": "0"});
    209291        $('#select_phone').hide();
    210292        $('#submit_form_button').hide();
     
    212294
    213295    //切换免密登录
    214     $('#phone-login').click(function (){
     296    $('#phone-login').click(function () {
    215297        $(this).hide();
    216298        $('#name-or-email-login').show();
     
    219301        $('.user-pass-wrap').hide();
    220302
    221         $('#wp-submit').val('登录').css({"display":"none","margin-right":"0"});
     303        $('#wp-submit').val('登录').css({"display": "none", "margin-right": "0"});
    222304        $('#select_phone').show();
    223305        $('#submit_form_button').show();
     
    249331
    250332    //免密登录按钮
    251     $('#submit_form_button').click(function (){
     333    $('#submit_form_button').click(function () {
    252334        var phone = $("#user_phone").val();
    253335        if (phone === '' || !phone.match(/^1[3-9]\d{9}$/)) {
     
    260342
    261343    //登录按钮
    262     $('#sms_login_button').click(function (){
     344    $('#sms_login_button').click(function () {
    263345        operaticon = 'smsLogin';
    264346        obj.validate()
     
    266348
    267349    //输入国别号弹出下拉
    268     $('#country_code').focus(function (){
     350    $('#country_code').focus(function () {
    269351        $('#dropdown-menu').show()
    270352    })
    271     $('#country_code').blur(function (){
     353    $('#country_code').blur(function () {
    272354        // $('#dropdown-menu').hide()
    273355    })
     
    275357
    276358    //选择国别号弹出下拉
    277     $('#btn-down').click(function (){
    278         if($("#dropdown-menu").is(":hidden")){
     359    $('#btn-down').click(function () {
     360        if ($("#dropdown-menu").is(":hidden")) {
    279361            $('#dropdown-menu').show()
    280         }else {
     362        } else {
    281363            $('#dropdown-menu').hide()
    282364        }
    283365    })
    284366    //选择国别号下拉点击
    285     $("#dropdown-menu").children("li").click(function(e) {
     367    $("#dropdown-menu").children("li").click(function (e) {
    286368        $(this).addClass("active").siblings("li").removeClass("active");
    287369        var code = $(this).data('value');//点击时 当前li的值
  • vaptcha-sms/trunk/options.php

    r2511904 r2513195  
    2222            <div class='vaptcha-badge'></div>
    2323            <div>
    24                 <h2><?php _e('手机登录注册', 'vaptcha') ?></h2>
    25                 <p class="vaptcha-about-text"><?php _e( '由智能人机验证服务商VAPTCHA提供的手机注册插件。短信单价经过补贴后远低于市场价,并集成了先进的人机验证策略,不用担心短信被刷,同时支持设备免密登录,pc/手机/平板均可。', 'vaptcha' ); ?>
     24                <h2><?php _e('VAPTCHA-SMS', 'vaptcha') ?></h2>
     25                <p class="vaptcha-about-text"><?php _e( '为了避免冲突,VAPTCHA及VAPTCHA-SMS仅能同时启用其中一个插件;短信单价经过补贴后远低于市场价,低至2.8分/条,插件安装即赠送30条测试短信,超出请自行充值后使用。', 'vaptcha' ); ?>
    2626            </div>
    2727        </div>
     
    5757                <tr>
    5858                    <th class="form-title"><b style="font-size: 16px;"><?php _e('短信接口设置', 'vaptcha') ?></b></th>
    59                     <td>
    60                         <?php _e( '(登录VAPTCHA - 短信接口  -  获取参数。注意,默认模板签名被公用,到达率较低,建议使用自定义短信模板,自定义模板内容只能包含验证码一个变量)', 'vaptcha' ); ?>
     59                    <td style="width: 1000px">
     60                        <?php _e( '(登录VAPTCHA - 短信接口  -  获取参数。默认模板签名被公用,到达率较低,建议使用自定义短信模板,自定义模板内容只能包含验证码一个变量)', 'vaptcha' ); ?>
    6161                    </td>
    6262                </tr>
     
    8686                        </fieldset>
    8787                    </td>
    88                     <td class='descript'><?php _e('建议使用自定义模板,示例:【XX网站】您的验证码是{变量},请在十分钟内输入', 'vaptcha') ?></td>
     88                    <td class='descript' style="width: 550px"><?php _e('建议使用自定义模板,示例:【XX网站】您的验证码是{变量},请在十分钟内输入', 'vaptcha') ?></td>
    8989                </tr>
    9090                <tr>
Note: See TracChangeset for help on using the changeset viewer.