瀏覽代碼

更新验证码

sandm 1 年之前
父節點
當前提交
84ca61115f
共有 1 個文件被更改,包括 149 次插入52 次删除
  1. 149 52
      public/themes/default/views/app/common/ajax/per_login.blade.php

+ 149 - 52
public/themes/default/views/app/common/ajax/per_login.blade.php

@@ -10,6 +10,9 @@
                 <!--普通用户登录-->
                 <div class="login-type user-login">
                     <form id="form_account" action="{{route('login.account')}}" method="post">
+                        <input type="hidden" name="ticket" id="ticket">
+                        <input type="hidden" name="bizState" id="bizState">
+                        <input type="hidden" name="randstr" id="randstr">
                         {{ csrf_field() }}
                         <div id="account"></div>
                         <div id="message_account"></div>
@@ -36,6 +39,9 @@
                 <!--手机登录-->
                 <div class="login-type mob-login" style="display: none;">
                     <form id="form_mobile" action="{{route('login.sms')}}" method="post">
+                        <input type="hidden" name="ticket" id="ticket1">
+                        <input type="hidden" name="bizState" id="bizState1">
+                        <input type="hidden" name="randstr" id="randstr1">
                         {{ csrf_field() }}
                         <div id="mobile"></div>
                         <div id="message_mobile"></div>
@@ -83,65 +89,157 @@
 </div>
 <script type="text/javascript" src="{{ theme_asset('gt/gt.js') }}"></script>
 <script type="text/javascript" src="{{ theme_asset('gt/gt.handle.js') }}"></script>
+<script src="https://captcha.253.com/TCaptcha.js"></script>
 @include('module.widgets.thirdlogin', ['redirect_url'=>$redirect_url])
 <script>
     $(function () {
-        var is_need_geetest=0;//全局,是否使用极验.
-        var login_type=1;//登录模式,1用户账号登录,2用户手机登录,3企业登录.
-        var gt_call_back=function(captchaObj) {
-            captchaObj.onReady(function () {
-                //极验加载完成
-            });
-            captchaObj.onSuccess(function () {
-                ajax_login(login_type,captchaObj);
+        // var is_need_geetest=0;//全局,是否使用极验.
+        // var login_type=1;//登录模式,1用户账号登录,2用户手机登录,3企业登录.
+        // var gt_call_back=function(captchaObj) {
+        //     captchaObj.onReady(function () {
+        //         //极验加载完成
+        //     });
+        //     captchaObj.onSuccess(function () {
+        //         ajax_login(login_type,captchaObj);
+        //
+        //     });
+        //     captchaObj.onError(function () {
+        //         show_error(login_type,"请先进行验证");
+        //     });
+        //     captchaObj.onClose(function () {
+        //         show_error(login_type,"请先进行验证");
+        //     });
+        //     $('.login-account').on('click', function () {
+        //         login_type=1;
+        //         clean_message();
+        //         if (is_need_geetest==1){
+        //             captchaObj.bindForm("#form_account");
+        //             captchaObj.verify();
+        //         }
+        //         else{
+        //             ajax_login(login_type,captchaObj);
+        //         }
+        //
+        //     });
+        //
+        //     $('.login-mobile').on('click', function () {
+        //         login_type=2;
+        //         clean_message();
+        //         if (is_need_geetest==1){
+        //             captchaObj.bindForm("#form_mobile");
+        //             captchaObj.verify();
+        //         }
+        //         else{
+        //             ajax_login(login_type,captchaObj);
+        //         }
+        //     });
+        //
+        //     $('.login-company').on('click', function () {
+        //         login_type=3;
+        //         clean_message();
+        //         if (is_need_geetest==1){
+        //             captchaObj.bindForm("#form_company");
+        //             captchaObj.verify();
+        //         }
+        //         else{
+        //             ajax_login(login_type,captchaObj);
+        //         }
+        //     });
+        // };
+        //
+        // gt_init(gt_call_back);//初始化极验
+        var captcha_callback = function(res){
+            if(res.hasOwnProperty('errorMessage')){
+                alert(res.errorMessage)
+            }
+            if(res.ret == 0){
+                console.log('行为验证通过');
+                $("#ticket").val(res.ticket);
+                $("#bizState").val(res.bizState);
+                $("#randstr").val(res.randstr);
+                ajax_login(1);
+            }else{
+                console.log('用户主动关闭验证码')
+            }
+            console.log('callback:', res);
+        }
 
-            });
-            captchaObj.onError(function () {
-                show_error(login_type,"请先进行验证");
-            });
-            captchaObj.onClose(function () {
-                show_error(login_type,"请先进行验证");
-            });
-            $('.login-account').on('click', function () {
-                login_type=1;
-                clean_message();
-                if (is_need_geetest==1){
-                    captchaObj.bindForm("#form_account");
-                    captchaObj.verify();
-                }
-                else{
-                    ajax_login(login_type,captchaObj);
-                }
+        var mobile_captcha_flag = false;
+        var mobile_captcha_callback = function(res){
+            if(res.hasOwnProperty('errorMessage')){
+                alert(res.errorMessage)
+            }
+            if(res.ret == 0){
+                mobile_captcha_flag = true;
+                console.log('行为验证通过');
+                $("#ticket1").val(res.ticket);
+                $("#bizState1").val(res.bizState);
+                $("#randstr1").val(res.randstr);
+                submit_data={
+                    "mobile":$("input[name='mobile']").val(),
+                    "type":"login"
+                };
+                $.ajax({
+                    method: 'post',
+                    url: '{{route('sms.send')}}',
+                    data: submit_data,
+                    beforeSend:function () {
+                        // console.log('请求开始');
+                        $(".errinfo").text("");
+                        $(".errinfo").removeClass("errinfo");
 
-            });
+                    },
+                    complete:function() {
+                        console.log('请求结束');
+                    },
+                    success: function (data) {
+                        // console.log(data);
+                        $("#message_mobile").addClass("successinfo");
+                        $("#message_mobile").text("发送成功,请注意查收");
+                        settime();
+                    },
+                    error: function (errorData) {
+                        // console.log(errorData);
+                        if (errorData.status==422) {//验证错误
+                            $.each(errorData.responseJSON.errors,function (key,val) {
+                                $("#"+key).addClass("errinfo");
+                                $("#"+key).text(val[0]);
+                            });
+                        }
+                        else if(errorData.status==400) {//业务错误
+                            $("#message_mobile").addClass("errinfo");
+                            $("#message_mobile").text(errorData.responseJSON.message);
+                        }
+                    }
+                });
+            }else{
+                console.log('用户主动关闭验证码')
+            }
+            console.log('callback:', res);
+        }
 
-            $('.login-mobile').on('click', function () {
-                login_type=2;
-                clean_message();
-                if (is_need_geetest==1){
-                    captchaObj.bindForm("#form_mobile");
-                    captchaObj.verify();
-                }
-                else{
-                    ajax_login(login_type,captchaObj);
-                }
-            });
+        var captcha = new TencentCaptcha('196587903', captcha_callback, {});
+        $('.login-account').on('click', function () {
+            captcha.show();
 
-            $('.login-company').on('click', function () {
-                login_type=3;
-                clean_message();
-                if (is_need_geetest==1){
-                    captchaObj.bindForm("#form_company");
-                    captchaObj.verify();
-                }
-                else{
-                    ajax_login(login_type,captchaObj);
-                }
-            });
-        };
+        });
+
+        var mobile_captcha = new TencentCaptcha('196587903', mobile_captcha_callback, {});
+        $('.btn-getcode').on('click', function () {
+            mobile_captcha.show();
 
-        gt_init(gt_call_back);//初始化极验
+        });
+
+        $('.login-mobile').on('click', function () {
+            login_type=2;
 
+            if (mobile_captcha_flag){
+                ajax_login(2);
+            }
+            else{
+                alert('验证码组件异常')
+            }
+        });
 
         $(document).on("click",".switch-title span",function () {
             var index = $(this).index();
@@ -193,7 +291,7 @@
         });
 
 
-        function ajax_login(type, captchaObj) {
+        function ajax_login(type) {
             if (type==1) {
                 $.ajax({
                     method: 'post',
@@ -225,7 +323,6 @@
                         else if(errorData.status==400) {//业务错误
                             $("#message_account").addClass("errinfo");
                             $("#message_account").text(errorData.responseJSON.message);
-                            is_need_geetest=errorData.responseJSON.errors.is_need_geetest;
                         }
                     }
                 });