{% load static %}
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>Login | SOC</title>

    <link rel="stylesheet" type="text/css" href="{% static 'console/layui/css/layui.css' %}"/>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            overflow: hidden
        }

        body {
            background: #267b6e;
        }

        body:after {
            content: '';
            background-repeat: no-repeat;
            background-size: cover;
            -webkit-filter: blur(3px);
            -moz-filter: blur(3px);
            -o-filter: blur(3px);
            -ms-filter: blur(3px);
            filter: blur(3px);
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: -1;
        }

        .layui-container {
            width: 100%;
            height: 100%;
            overflow: hidden
        }

        .admin-login-background {
            width: 360px;
            height: 300px;
            position: absolute;
            left: 50%;
            top: 40%;
            margin-left: -180px;
            margin-top: -100px;
        }

        .logo-title {
            text-align: center;
            letter-spacing: 3px;
            padding: 14px 0;
        }

        .logo-title h1 {
            color: #009688;
            font-size: 28px;

        }

        .logo-title h2 {
            color: #009688;
            font-size: 16px;

        }

        .login-form {
            background-color: #fff;
            border: 1px solid #fff;
            border-radius: 3px;
            padding: 14px 20px;
            box-shadow: 0 0 8px #eeeeee;
        }

        .login-form .layui-form-item {
            position: relative;
        }

        .login-form .layui-form-item label {
            position: absolute;
            left: 1px;
            top: 1px;
            width: 38px;
            line-height: 36px;
            text-align: center;
            color: #d2d2d2;
        }

        .login-form .layui-form-item input {
            padding-left: 36px;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="login-form">
            <form class="layui-form" onsubmit="return false">
                <div class="layui-form-item logo-title">
                    <h1>MySOC</h1>
                    <hr style="width: 80%;margin: auto">
                    <h2><i>Welcome to MySOC</i></h2>
                </div>

                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-username" for="username"></label>
                    <input type="text" name="username" lay-verify="user" placeholder="Username" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password" for="password"></label>
                    <input type="password" id="password" name="password" lay-verify="pass" autocomplete="off"
                           placeholder="Password" class="layui-input">
                </div>

                <div class="layui-form-item">
{#                    <button class="layui-btn" style="width: 27.6%" lay-filter="register">Register</button>#}
                    <button class="layui-btn" style="width: 100%" type="submit" lay-submit lay-filter="login">Login</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="{% static '/js/layui/layui.js' %}"></script>
<script>
    layui.use(['form', 'layer', 'jquery'], function () {
        let form = layui.form,
            $ = layui.jquery,
            layer = layui.layer;

        $.ajaxSetup({
            headers: {"X-CSRFToken": '{{ csrf_token }}'},
        });

        //监听提交
        form.on('submit(login)', function (data) {
            //自定义验证规则
            form.verify({
                user: function (value) {
                    if (value.length < 4) {
                        return '用户名至少得4个字符啊';
                    }
                },
                pass: [/(.+){5,12}$/, '密码必须5到12位']
            });

            $.ajax({
                url: '/app/login',
                type: 'POST',
                data: data.field,
                success: function (res) {
                    if (res.code === 0) {
                        layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                            window.location = '/';
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: 2000});
                    }
                }
            });
            return false;
        });
    });

</script>
</body>

</html>