<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" href="/static/favicon.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon" />
    <title>{{g.title}}</title>
    <link rel="stylesheet" type="text/css" href="/static/css/site.css?date={{g.version}}">
    <link rel="stylesheet" type="text/css" href="/static/css/login.css?date={{g.version}}">
</head>
<body>
    <div class="main">
        <div class="login">
            <div class="account">
                <form class="loginform" method="post" action="/login" onsubmit="return false;">
                    <div class="rlogo">{{g.title}}</div>
                    <div class="line"><input class="inputtxt" value="" name="username" datatype="*" nullmsg="{{data['lan']['N1']}}" errormsg="{{data['lan']['N2']}}" placeholder="{{data['lan']['N3']}}" type="text"><div class="Validform_checktip"></div></div>
                    <div class="line"><input class="inputtxt" name="password" value="" datatype="*" nullmsg="{{data['lan']['N4']}}" errormsg="{{data['lan']['N5']}}" placeholder="{{data['lan']['N6']}}" type="password"><div class="Validform_checktip"></div></div>
                    <div style="color: red;position: relative;top: -14px;" id="errorStr"></div>
                        <div class="line yzm" style="top: -5px;
                            {% if not session['code'] %}
                                display:none;
                            {% endif %}
                        ">
                        <input type="text" class="inputtxt" name="code" nullmsg="{{data['lan']['N7']}}" errormsg="{{data['lan']['N8']}}" datatype="*" placeholder="{{data['lan']['N9']}}">
                        <div class="Validform_checktip"></div>
                        <img width="100" height="40" class="passcode" onClick="this.src=this.src.split('?')[0] + '?'+new Date().getTime()" src="/code" style="border: 1px solid #ccc; float: right;" title="{{data['lan']['N10']}}">
                    </div>
                    <div class="login_btn"><input id="login-button" value="{{data['lan']['N11']}}" type="submit"></div>
                    <p class="pwinfo" style="display:none">{{data['lan']['N12']}}</p>
                    <a class="resetpw" href="https://forum.aapanel.com/d/16-how-to-reset-password-for-aapanel-linux-6-x" target="_blank">{{data['lan']['N13']}}</a>
                </form>
            </div>
            <div class="scanCode" style="display: none;">
                <div class="titles"><span>{{data['lan']['QR_CORE_LOGIN']}}</span></div>
                <div class="qrCode" id="qrcode"></div>
                <div class="scanTip">
                    <div class="list_scan">
                        <img src="/static/img/sCan.png" />
                        <span>
                            {{data['lan']['OPEN']}}
                            <a href="javascript:;" class="btlink">
                                {{data['lan']['BT_SMALL_P']}}
                                <div class="weChatSamll"><img src="https://app.bt.cn/static/app.png"><em></em></div>
                            </a>
                        </span>
                        <span>{{data['lan']['SCAN_LOGIN']}}</span>
                    </div>
                </div>
            </div>
            <div class="entrance" style="display: none;">
                <div class="bg_img"></div>
                <div class="tips">
                    <span><img src="/static/img/safety_ico.png"><span>{{data['lan']['SCAN_MORE_SAFETY']}}</span></span>
                    <em></em>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="/static/js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/static/language/zh-cn.js"></script>
    <script type="text/javascript" src="/static/layer/layer.js"></script>
    <script type="text/javascript" src="/static/js/jquery.qrcode.min.js"></script>
    <script type="text/javascript" src="/static/js/Validform_v5.3.2_min.js"></script>
    <script type="text/javascript" src="/static/js/md5.js"></script>
    <script type="text/javascript">
        function Wreset() {
            var w = $(window).width();
            var yzmw = $(".login .line").width() - 140;
            if ($(".yzm").is(":visible") && w > 640) {
                $(".login").css({ "height": "365px", "margin-top": "-230px" });
            }
            else {
                $(".login").removeAttr("style")
            }
            $(".login .yzm .inputtxt").width(yzmw);
        }
        $(function () {
            Wreset();
            var setTime = '';
            function controlTime() {
                $.get('/public?name=app&fun=is_scan_ok', function (res) {
                    if (res.status) {
                        layer.msg("{{data['lan']['SCAN_SUCCESS']}}", { icon: 1 });
                        clearInterval(setTime);
                        loginAdmin(res.msg);
                    }
                });
            }
            function loginAdmin(key) {
                $.get('/public?name=app&fun=set_login', { secret_key: key }, function (res) {
                    layer.msg(res.msg, { icon: res.status ? 1 : 2 })
                    if (res.status) {
                        layer.msg("{{data['lan']['SAFE_LOGGING_NOW']}}", { time: 0, shade: [0.4, '#fff'], icon: 16 });
                        setTimeout(function () {
                            location.href = '/';
                        }, 1000);
                    }
                });
            }
            $('.bg_img').click(function (event) {
                if ($(this).hasClass('pc')) {
                    $(this).removeClass('pc');
                    $('.scanCode').hide().prev().show();
                    clearInterval(setTime);
                    $('.tips>span>span').html("{{data['lan']['SCAN_MORE_SAFETY']}}");
                } else {
                    $(this).addClass('pc');
                    $('.account').hide().next().show();
                    $('.tips>span>span').html("{{data['lan']['USER_LOGIN']}}");
                    setTime = window.setInterval(controlTime, 2000);
                }
            });
        })
        window.onresize = function () {
            Wreset();
        }
    </script>
    <script type="text/javascript">
        $(function () {
            $(".loginform").Validform({
                tiptype: function (msg, o, cssctl) {
                    if (!o.obj.is("form")) {
                        var objtip = o.obj.siblings(".Validform_checktip");
                        cssctl(objtip, o.type);
                        objtip.text(msg);
                    }
                }
            });
        });

        $('#login-button').click(function () {
            var username = $("input[name='username']").val();
            var password = $("input[name='password']").val();
            var code = $("input[name='code']").val();
            if (username == '' || password == '') {
                layer.msg("{{data['lan']['FORM_ERR']}}", { icon: 2 });
                return;
            }

            var data = { username: username, password: md5(md5(password) + '' + '_bt.cn'), code: code }
            var loadT = layer.msg("{{data['lan']['JS2']}}", { icon: 16, time: 0, shade: [0.3, '#000'] });
            $.post('/login', data, function (rdata) {
            	if(rdata == '1'){
                    layer.close(loadT);
            		layer.open({
                        type:1,
                        title:false,
                        area: ['350px', '285px'],
                        content:'<div class="verification_view">\
                                    <div class="v_title">Google authentication</div>\
                                    <div class="v_input"><input type="text" class="v_code" name="v_code" placeholder="Verification code"/></div>\
                                    <div class="v_btn"><input id="auth_verif_btn" value="log in" type="submit"></div>\
                                    <div class="v_tips">* Please use the Google Authenticator app to get the verification code.<br><a target="_blank" href="https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=37437"  class="btlink">Unable to verify, click help</a></div>\
                                </div>',
                        success:function(){
                            // 点击验证登录
                            $('[name="v_code"]').keyup(function(e){
                                if(e.keyCode == 13){
                                    $('#auth_verif_btn').click();
                                }
                            });
                            $('#auth_verif_btn').click(function(e){
                                data['vcode'] = $('[name="v_code"]').val();
                                var loadT = layer.msg("{{data['lan']['JS2']}}", { icon: 16, time: 0, shade: [0.3, '#000'] });
                                $.post('/login', data, function (rdata) {
                                    layer.close(loadT);
                                    if(!rdata.status){ 
                                        layer.msg(rdata.msg, { icon: 2 });
                                        return false;
                                    }
                                    layer.msg(rdata.msg, { icon: 16, time: 0, shade: [0.3, '#000'] });
                                    window.location.href = '/';
                                });
                            });
                        }
                    });
                    return false;
            	}
                layer.close(loadT);
                if (!rdata.status) {
                    $("#errorStr").html(rdata.msg);
                    $("input[name='password']").val('');
                    num = rdata.msg.substring(rdata.msg.indexOf('[') + 1, rdata.msg.indexOf(']'));
                    if (num < 5) {
                        $(".yzm").show();
                        $(".login").css("height", "332px");
                        $("input[name='code']").val('');
                    }
                    $(".yzm").show();
                    Wreset();
                    $(".passcode").click();
                    layer.msg(rdata.msg, { icon: 2 });
                    return;
                }

                layer.msg(rdata.msg, { icon: 16, time: 0, shade: [0.3, '#000'] });
                window.location.href = '/';
            });
        });

    </script>
</body>
</html>