<!DOCTYPE html>
<html class="adminlogin">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no" />
    <meta name="description" content="{{configs.siteName}}">
    <meta property="og:type" content="website" />
    <meta name="author" content="DoraCMS">
    <title>
        DoraCMS Admin Login
    </title>
    <!-- 引入组件库 -->
    <script src="{{staticRootPath}}/plugins/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
    <link href="{{staticRootPath}}/plugins/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <script src="{{staticRootPath}}/plugins/twitter-bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript">
    </script>
    <link href="{{staticRootPath}}/plugins/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script src="{{staticRootPath}}/plugins/avalon.js/2.2.7/avalon.min.js"></script>
    <script src="{{staticRootPath}}/plugins/layer/layer.js"></script>
    <link rel="stylesheet" href="{{staticRootPath}}/plugins/layer/theme/default/layer.css">

    <!--default theme-->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="{{staticRootPath}}/plugins/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="{{staticRootPath}}/plugins/respond.js/1.4.2/respond.min.js"></script>
      <script src="{{staticRootPath}}/plugins/json3/3.3.2/json3.min.js"></script>
      <script src="{{staticRootPath}}/plugins/es6-promise/4.0.5/es6-promise.min.js"></script>
    <![endif]-->
    <input type="hidden" value="{{lsk}}" id="sysKeys">
    <style>
        input:-internal-autofill-previewed,
        input:-internal-autofill-selected {
            -webkit-text-fill-color: #ffffff;
            transition: background-color 5000s ease-out 0.5s;
        }

        .adminlogin {
            height: 100%;
            background-repeat: no-repeat;
            background: url('{{staticRootPath}}/themes/users/images/login_background_hd.jpg');
            background-size: cover;
            position: relative;
        }

        .adminlogin body {
            background: none;
            height: 100%;
        }

        .adminlogin .login-container {
            background-clip: padding-box;
            background: transparent;
            position: absolute;
            width: 350px;
            height: 300px;
            top: 50%;
            left: 50%;
            margin-left: -150px;
            margin-top: -210px;
        }

        .adminlogin .login-container .loginForm {

            /* background: #fff; */
            border-radius: 0px;
            position: absolute;
            background: rgb(0, 0, 0, 0.3);
            box-shadow: 0px 3px 6px rgb(0 0 0 / 20%);
        }

        .adminlogin .login-container .loginForm .form-title {
            border-bottom: 1px solid #e8eaec;
            padding: 14px 16px;
            line-height: 1;
            margin-bottom: 10px;
        }

        .adminlogin .login-container .loginForm .form-content {
            padding: 15px 12px;
        }

        .adminlogin .login-container .form-title p {
            display: inline-block;
            width: 100%;
            height: 36px;
            line-height: 36px;
            font-size: 30px;
            color: #fff;
            font-weight: 700;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            margin-bottom: 15px;
            text-align: center;
            text-shadow: 0px 1px 2px rgb(0 0 0 / 50%);
        }

        .adminlogin .login-container .loginForm .input-group {
            margin-bottom: 25px;
        }

        .adminlogin .login-container .loginForm .input-group input {
            border-width: 0px;
            background-image: none;
            background-color: transparent !important;
            border: none !important;
            color: #FFFFFF !important;
            text-shadow: 0px 1px 2px rgb(0 0 0 / 30%);
            box-shadow: none;
            border-radius: 0;
        }

        .adminlogin .login-container .loginForm .input-group input:focus {
            background-color: transparent !important;
        }

        .adminlogin .login-container .loginForm .input-group .input-group-addon {
            border-radius: 0;
            background: none;
            border: none;
            color: #fff;
            font-size: 18px;
        }

        .adminlogin .login-container .admin-logo-title h3 {
            color: #99a9bf;
            font-size: 35px;
            text-align: center;
            font-weight: normal;
            margin: 40px 0;
        }

        .adminlogin .login-container .input-group .imageCode-img {
            width: 100px;
            height: 94%;
            position: absolute;
            right: 4px;
            top: 1px;
        }

        .adminlogin .login-container .btn-primary {
            width: 100%;
        }

        .adminlogin .login-container .login-pannel {
            position: relative;
        }
    </style>
</head>

<body>
    <div class="container" style="height: 100%;">
        <div class="col-md-12" style="height: 100%;">

            <!--用户登录模块-->
            <div class="col-md-4 login-container" ms-controller="adminUserlogin">
                <div class="form-title">
                    <p><b style="color:#1D8CE0;">Dora</b>CMS</p>
                </div>
                <div class="login-pannel">

                    <form name="loginForm" class="loginForm" ms-validate="@validate">

                        <div class="form-content">
                            <div class="input-group">
                                <span class="input-group-addon" id="basic-addon1"><i class="fa fa-user"></i></span>
                                <input type="text" class="form-control" name="userName" ms-duplex="@userName"
                                    placeholder="请输入用户名"
                                    ms-rules="{required:true, pattern: /^[a-zA-Z][a-zA-Z0-9_]{4,11}$/ }"
                                    data-required-message="用户名不能为空" data-message="请输入正确的用户名">
                            </div>

                            <div class="input-group">
                                <span class="input-group-addon" id="basic-addon1"><i class="fa fa-lock"></i></span>
                                <input type="password" class="form-control" name="password" placeholder="请输入密码"
                                    ms-duplex="@password"
                                    ms-rules="{required: true,pattern: /(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{5,}/}"
                                    data-required-message="密码不能为空" data-message="请输入6-12个字符">
                            </div>

                            {% if showImgCode %}
                            <div class="input-group">
                                <span class="input-group-addon" id="basic-addon1"><i class="fa fa-random"></i></span>
                                <input type="text" class="form-control imageCode-input" name="imageCode"
                                    placeholder="请输入验证码" ms-duplex="@imageCode" ms-rules="{required: true}"
                                    data-required-message="验证码不能为空" data-message="请输入正确的验证码">
                                <img style="z-index:2" ms-attr="{src: @imgCodeUrl}" class="imageCode-img"
                                    ms-on-click="reSetImgCode" />
                            </div>
                            {% endif %}
                            <div id="ul-s5">
                                <button type="submit" class="btn btn-primary">登录</button>&nbsp;
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</body>
<script>
    /**
     * 
     * adminlogin avalon controller
     * 
     */
    layer.config({
        extend: 'blue/layer.css', //加载您的扩展样式,它自动从theme目录下加载这个文件
        skin: 'layui-layer-blue' //layui-layer-orange这个就是上面我们定义css 的class
    });
    var msgTime = 800;

    function getAjaxData(url, success = () => {}, type = 'get', params = {}, error = () => {}) {
        layer.load(2, {
            shade: [0.3, '#000']
        });
        var baseParams = {
            url: url,
            type: type.toLocaleUpperCase(),
            success: function (result) {
                layer.closeAll('loading');
                if (result.status === 500) {
                    layer.msg(result.message, {
                        icon: 2,
                        shade: [0.001, '#000'],
                        zIndex: 999999999,
                        time: msgTime
                    });
                    error && error();
                } else if (result.status === 401) {
                    layer.confirm(result.message, {
                        title: getSysValueByKey('sys_layer_confirm_title'),
                        btn: getSysValueByKey('sys_layer_confirm_btn_yes'),
                        yes: function (index) {
                            layer.close(index);
                        }
                    })
                } else {
                    success && success(result);
                }
            },
            error: function (d) {
                console.log('error:', d)
                layer.msg(d.message, {
                    icon: 2,
                    time: msgTime
                });
            }
        };
        if (type == 'post') {
            baseParams = Object.assign({}, baseParams, {
                data: params,
            })
        } else {
            if (url.indexOf('?') >= 0) {
                baseParams.url = url;
            } else {
                baseParams.url = url;
            }
        }
        $.ajax(baseParams);
    }

    var adminLoginVm = avalon.define({
        $id: 'adminUserlogin',
        password: '',
        userName: '',
        message: '',
        imageCode: "",
        showErr: false,
        imgCodeUrl: "/api/getImgCode",
        reSetImgCode: function () {
            adminLoginVm.imgCodeUrl = "/api/getImgCode?" + Math.random();
        },
        validate: {
            onError: function (reasons) {
                reasons.forEach(function (reason) {
                    console.log(reason.getMessage())
                })
            },
            onValidateAll: function (reasons) {
                if (reasons.length) {
                    console.log('有表单没有通过', reasons)
                    adminLoginVm.showErr = true;
                    adminLoginVm.message = reasons[0].message;
                    layer.msg(reasons[0].message, {
                        icon: 2,
                        shade: [0.001, '#000'],
                        time: 800
                    });
                } else {
                    console.log('全部通过');
                    var params = {
                        userName: adminLoginVm.userName,
                        password: adminLoginVm.password,
                        imageCode: adminLoginVm.imageCode
                    }
                    getAjaxData('/api/admin/doLogin', function (data) {
                        if (data.status == 200) {
                            window.location.href = "/admin/dashboard";
                        }
                    }, 'post', params, function () {
                        adminLoginVm.reSetImgCode();
                    })
                }
            }
        }
    })
</script>

</html>