{{ define "kas/settings.htm" }}
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <title>系统设置 - 后台管理 - 看丽人</title>
    <script type="text/javascript">
        const ISGOKEEP = true;
    </script>
    {{ template "_common.htm" .}}
    <script type="text/javascript">
        LoadMemberInfo();
    </script>
</head>

<body>
    {{ template "kas/_header.htm" .}}
    <main role="main">
        <div class="album py-3 bg-light">
            <div class="container">
                {{ template "kas/_nav.htm" .}}
                <div class="alert alert-dark border-bottom"><a href="/kas/settings">系统设置</a> > 密码设置</div>
                <form class="form-signin" id="frmSettings">
                    <div class="row">
                        <div class="col-md-12">
                            <label for="iptMid">密码设置</label>
                        </div>
                    </div>
                    <div class="py-2">
                        <label for="iptOldPassword" class="sr-only">输入旧密码</label>
                        <input name="old_password" type="password" id="iptOldPassword" class="form-control"
                            placeholder="输入旧密码" required="" autofocus="">
                    </div>
                    <div class="py-2">
                        <label for="iptNewPassword" class="sr-only">输入新密码</label>
                        <input name="new_password" type="password" id="iptNewPassword" class="form-control"
                            placeholder="输入新密码，最少6位" required="">
                    </div>
                    <div class="py-2">
                        <label for="iptReNewPassword" class="sr-only">确认新密码</label>
                        <input name="re_password" type="password" id="iptReNewPassword" class="form-control"
                            placeholder="确认新密码" required="">
                    </div>
                    <div class="py-2">
                        <button class="btn btn-danger btn-block" type="button" id="btnSave">设置</button>
                    </div>
                </form>
            </div>
        </div>

    </main>
    {{ template "kas/_footer.htm" .}}
    <script type="text/javascript">
        var gokeep_token = GetCookie(TokenName())
        if (gokeep_token == null) {
            DirectTo("/kas");
        }
        $('#btnSave').click(function (event) {
            $.ajax({
                type: "POST",
                dataType: 'json',
                data: $("#frmSettings").serialize(),
                url: "/api/v1/auth/member/reset_password",
                beforeSend: function (xhr) {
                    xhr.setRequestHeader('Authorization', 'Bearer ' + gokeep_token);
                }
            }).done(function (data) {
                Log(data);
                if (data.code == 0) {
                    ShowMsg("设置密码成功");
                    $("#iptOldPassword").val("");
                    $("#iptNewPassword").val("");
                    $("#iptReNewPassword").val("");
                } else if (data.code == 3201) {
                    ShowMsg("请设置正确的密码和新密码");
                } else if (data.code == 3202) {
                    ShowMsg("两次密码输入不一致");
                } else {
                    ShowMsg("设置密码失败");
                }
            }).fail(function (data) {
                Log("fail:", data);
                ShowMsg("设置密码失败");
            });
        });
    </script>
</body>

</html>
{{ end }}