










<script>

    function isEmpty(str) {
        return str == null || str == undefined || str.length == 0;
    }

    function isNotEmpty(str) {
        return str !== null && str !== undefined && str.length > 0;
    }

    function showMsg(type, title) {
        switch (type) {
            case "success":
                layui.layer.msg(title, {icon: 1, offset: '100px'});
                break;
            case "fail":
                layui.layer.msg(title, {icon: 2, offset: '100px'});
                break;
            case "info":
                layui.layer.msg(title, {icon: 0, offset: '100px'});
                break;

        }
    }

    function showDialog(title) {
        var loadIndex = layui.layer.msg(title, {
            icon: 16,
            shade: 0.2,
            time:-1,
            offset:'100px'
        });
        return loadIndex
    }
    function closeDialog(loadIndex) {
        layui.layer.close(loadIndex)
    }
</script>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>访问过于频繁 - 已被禁止</title>
    <style>
        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background-color: #f5f5f5;
            text-align: center;
            padding: 50px;
        }
        .captcha-container {
            background: white;
            border-radius: 8px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            padding: 30px;
            width: 400px;
            margin: 100px auto 0 auto;
        }
        h2 {
            color: #333;
            margin-bottom: 20px;
        }
        .captcha-input {
            padding: 10px;
            font-size: 16px;
            border: 2px solid #ddd;
            border-radius: 4px;
            width: 150px;
            outline: none;
            vertical-align: top;
        }
        .captcha-input:focus {
            border-color: #7a418f;
        }
        #img_captcha {
            height: 45px; 
            width: 160px; 
            border: 1px solid #ddd;
            border-radius: 4px;
            cursor: pointer;
            transition: all 0.3s;
            vertical-align: top;
        }
        #img_captcha:hover {
            transform: scale(1.05);
        }
        .submit-btn {
            background-color: #7a418f;
            color: white;
            border: none;
            padding: 12px 30px;
            font-size: 16px;
            border-radius: 4px;
            cursor: pointer;
            margin-top: 20px;
            width: 100%;
            transition: background-color 0.3s;
        }
        .submit-btn:hover {
            background-color: #5f3270;
        }
        .form-group {
            margin: 15px 0;
        }
        .captcha-wrapper {
            display: inline-block;
            text-align: center;
        }
    </style>
    <script type="text/javascript" src="/static/web/bootstrap3.3.5/js/jquery-3.6.0.js" ></script>
    <link rel="stylesheet" type="text/css"
          href="/static/web/layuiNew/css/layui.css"/>
    <script src="/static/web/layuiNew/layui.js"  type="text/javascript"></script>

    <script type="text/javascript" src="/static/web/bootstrap3.3.5/myjs/load.min.js" ></script>
</head>

<body>
    <div class="captcha-container">
        <h2>请先填写验证码后再进行滑块验证！</h2>
        <form id="captchaForm" action="" method="post">
            <div class="form-group">
                <div class="captcha-wrapper">
                    <input type="text" id="captcha" name="captcha" class="captcha-input" placeholder="请输入验证码"/>
                    <img alt="验证码"
                         title="点击更换"
                         id="img_captcha"/>
                </div>
            </div>

            <div class="form-group" id="captcha-box-d" style="display: none;">
                <div id="captcha-box" style="margin-left: 45px;"></div>
            </div>

            <div class="form-group">
                <button type="button" class="submit-btn" id="btnSubmit">提交验证</button>
            </div>

            <div class="form-group">
                <p style="font-size: 14px; color: #666; margin-top: 20px;">
                    无法通过验证，需要帮助?请联系：thurid@tsinghua.edu.cn<br/>
                    For assistance, please contact ：thurid@tsinghua.edu.cn
                </p>
            </div>
        </form>
    </div>

    <script>
        let captcha;
        function refreshCaptcha() {
            document.getElementById("img_captcha").src = "/static/images/kaptcha.jpg?t="
                + Math.random();
        }

        setTimeout(function () {
            refreshCaptcha();
        }, 500);

        $('#btnSubmit').click(function () {
            let captcha = $('#captcha').val();
            $.ajax({
                type: "get",
                url: "/login/captchaLimited",
                data: {captcha:captcha},
                dataType: 'json',
                success: function (result) {
                    if (result.success) {
                        $('#captcha-box-d').show();
                        showMsg("info","请进行滑块验证！");
                        setTimeout(function () {
                            showImageCaptcha()
                        }, 500);
                    } else {
                        showMsg("fail", result.msg);
                    }
                }
            });
        });

        // 在现有脚本中添加回车监听
        $('#captcha').keydown(function(event) {
            if (event.which === 13) { // 回车键的keyCode是13
                event.preventDefault(); // 阻止默认行为
                $('#btnSubmit').click(); // 触发提交按钮点击事件
            }
        });


        function showImageCaptcha() {
            // config 对象为TAC验证码的一些配置和验证的回调
            const config = {
                // 生成接口 (必选项,必须配置, 要符合tianai-captcha默认验证码生成接口规范)
                requestCaptchaDataUrl: "/login/genCaptcha",
                // 验证接口 (必选项,必须配置, 要符合tianai-captcha默认验证码校验接口规范)
                validCaptchaUrl: "/login/imageCaptchaCheck",
                // 验证码绑定的div块 (必选项,必须配置)
                bindEl: "#captcha-box",
                // 验证成功回调函数(必选项,必须配置)
                validSuccess: (res, c, tac) => {
                    // 销毁验证码服务
                    tac.destroyWindow();
                    console.log("验证成功，后端返回的数据为", res);
                    // 调用具体的login方法
                    // login(res.data.token)
                    showMsg("success","验证成功，马上跳转到首页！");
                    setTimeout(function (){
                        location.href = "/";
                    },1000)
                },
                // 验证失败的回调函数(可忽略，如果不自定义 validFail 方法时，会使用默认的)
                validFail: (res, c, tac) => {
                    console.log("验证码验证失败回调...")
                    // 验证失败后重新拉取验证码
                    tac.reloadCaptcha();
                },
                // 刷新按钮回调事件
                btnRefreshFun: (el, tac) => {
                    console.log("刷新按钮触发事件...")
                    tac.reloadCaptcha();
                },
                // 关闭按钮回调事件
                btnCloseFun: (el, tac) => {
                    console.log("关闭按钮触发事件...")
                    tac.destroyWindow();
                }
            }
            // 一些样式配置， 可不传
            // let style = {
            //     logoUrl: null// 去除logo
            //     // logoUrl: "/xx/xx/xxx.png" // 替换成自定义的logo
            // }
            // 这里分享一些作者自己调的样式供参考
            const style = {
                // 按钮样式
                btnUrl: "https://minio.tianai.cloud/public/captcha-btn/btn3.png",
                // 背景样式
                bgUrl: "/static/web/img2/a22.jpg",
                // logo地址
                logoUrl: null,
                // 滑动边框样式
                moveTrackMaskBgColor: "#6f5379",
                moveTrackMaskBorderColor: "#7a418f"
            }

            // -------------- 拉起TAC验证码 -----------------

            // 参数1： tac文件的URL地址前缀， 目录里包含 tac的js和css等文件，
            //      比如参数为: http://xxxx/tac/, 该js会自动加载 http://xxxx/tac/js/tac.min.js 、http://xxxx/tac/css/tac.css等
            //      具体的js文件可以在 https://gitee.com/tianai/tianai-captcha-web-sdk/releases/tag/1.2 下载
            // 参数2： tac验证码相关配置
            // 参数3： tac窗口一些样式配置
            window.initTAC("/static/web/tac", config, style).then(tac => {
                tac.init(); // 调用init则显示验证码
            }).catch(e => {
                console.log("初始化tac失败", e);
            })
        }
    </script>
</body>
</html>