<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../static/css/home.css">
    <title>登录</title>
    <script src="../static/js/jquery-3.5.1.min.js"></script>
    <script src="http://api.html5media.info/1.1.8/html5media.min.js"></script>
    <script src="../static/js/ip.js"></script>
    <script type="text/javascript">
        var cookie = {
            setCookie: function (cname, cvalue, exdays) {
                var d = new Date();
                d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                var expires = "expires=" + d.toGMTString();
                document.cookie = cname + "=" + cvalue + "; " + expires;
            },
            getCookie: function (name) {
                var arr = document.cookie.split('; ');
                for (var i = 0; i < arr.length; i++) {
                    var arr2 = arr[i].split('=');
                    if (arr2[0] == name) {
                        return arr2[1];
                    }
                }

                return '';
            },
            removeCookie: function (name) {
                cookie.setCookie(name, '', -1)
            }
        };

        function login(obj) {
            var phonenum = $(obj).parent().prev().prev().children("#phonenum").val();
            var password = $(obj).parent().prev().children("#password").val();
            var url_ = "http://"+url+":5000/bp_auth/login";
            $.ajax({
                type: "POST",
                url: url_,
                data: {
                    phonenum: phonenum,
                    password: password
                },
                success: function (data) {
                    cookie.setCookie('phonenum', phonenum, 30);
                    
                    if(data.code != 1){
                        window.location = "%%url_for('start.login')%%";
                    }else{
                        window.location = "%%url_for('start.personal')%%";
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    
                    alert(textStatus);
                    window.location = "%%url_for('start.login')%%";
                }
            });
        }
    </script>
</head>

<body>
    <div class="background">
        <video autoplay loop muted>
            <source src="../static/video/video.mp4" type="video/mp4" />
            Your Browser is no longer supported.
        </video>
    </div>

    <div class="login">
        <div class="logo_1"></div>
        <div class="form-item">
            <p style="padding-bottom:30px"><input id="phonenum" oninput="value=value.replace(/[^\d]/g,'')"
                    autocomplete="off" placeholder="电话号码" name="phonenum"></p>
            <p style="padding-bottom:30px"><input id="password" type="password" autocomplete="off" placeholder="登录密码"
                    name="password"></p>
            <p><input type="submit" value="登录" id="login" onclick="login(this)"
                    style="padding-left:0;margin-left:0;width:350px;background-color:white;color:#1f6f4a;cursor:pointer">
            </p>
        </div>

        <div class="reg-bar">
            <a class="reg" href="%%url_for('start.register')%%">立即注册</a>
            <a class="forget" href="%%url_for('start.forget')%%">忘记密码</a>
        </div>
    </div>
</body>

</html>
