<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title></title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />

    <link rel="stylesheet" type="text/css" th:href="@{/vendor/bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/fonts/font-awesome-4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/fonts/iconic/css/material-design-iconic-font.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/css/util.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/css/main.css}">
</head>

<body>

<div class="limiter">
    <div class="container-login100" th:style="'background-image:url(/images/bg.jpg);'">
        <div class="wrap-login100 p-l-40 p-r-40 p-t-30 p-b-25">
            <form method="post" class="login100-form validate-form">
                <div id="login-logo" class="p-b-15" style="text-align: center;">
                    <img style="width: 80px;" class="logoImage">
                </div>

                <span class="login100-form-title p-b-30">重置密码</span>

                <div class="wrap-input100 validate-input m-b-23" data-validate="请输入用户名">
                    <span class="label-input100">邮箱</span>
                    <input id="email" class="input100" type="text" name="email" readonly="readonly" th:value="${user.email}">
                    <span class="focus-input100" data-symbol="&#xf206;"></span>
                </div>

                <div class="wrap-input100 validate-input m-b-23"  data-validate="请输入密码">
                    <span class="label-input100">新密码</span>
                    <input id="password" class="input100" type="password" name="password" placeholder="请输入密码" required="密码不可为空">
                    <span class="focus-input100" data-symbol="&#xf190;"></span>
                </div>
                <input id="verifyCode" name="verifyCode" style="display: none" th:value="${user.verifyCode}">
                <div class="wrap-input100 validate-input" data-validate="请输入密码">
                    <span class="label-input100">重复密码</span>
                    <input id="password2" class="input100" type="password" name="password2" placeholder="请输入密码" required="密码不可为空">
                    <span class="focus-input100" data-symbol="&#xf190;"></span>
                </div>

                <div class="text-center p-t-6 p-b-20">
                    <span id="info" style="color: red" th:text="${result==null}?'&nbsp;':${result.msg}"></span>
                </div>
                <div class="container-login100-form-btn">
                    <div class="wrap-login100-form-btn">
                        <div class="login100-form-bgbtn"></div>
                        <button type="button" onclick="resetPassword(this)" class="login100-form-btn">重置密码</button>
                    </div>
                </div>


                <div class="flex-col-c p-t-10">
                    <a href="/page/login" class="txt2">返回登录</a>
                </div>
            </form>
        </div>
    </div>
</div>

<script th:src="@{/vendor/jquery/jquery-3.2.1.min.js}"></script>
<script th:src="@{/js/main.js}"></script>
<script type="text/javascript">
    function resetPassword(obj) {
        var email = $("#email").val();
        var password = $("#password").val();
        var password2 = $("#password2").val();
        var verifyCode = $("#verifyCode").val();
        if (password == null || password.trim() == ""
        || password2 == null || password2.trim() == "") {
            document.getElementById("info").innerText = "密码不可为空";
            return;
        }
        if (password != password2){
            document.getElementById("info").innerText = "密码不一致，请重新输入";
            return;
        }
        if (password.length>16 || password.length<6){
            document.getElementById("info").innerText = "密码应在6-16位";
            return;
        }
        var data = {"email":email, "password":password, "verifyCode":verifyCode};
        $.ajax({
            url:"/api/password/reset",
            type:"PUT",
            data:JSON.stringify(data),
            contentType: 'application/json; charset=utf-8',
            dataType:"json",
            timeout: 3000,
            success:function (result) {
                console.log(result);
                if (result.status != 2000) {
                    document.getElementById("info").innerText = result.msg;
                }else{
                    alert("修改成功,请前往登录");
                    document.location.href="/page/login";
                }
            }
        })
    }
</script>
</body>
</html>