{{ define "member/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>
  {{ template "_common.htm" .}}
</head>

<body>
  {{ template "_header.htm" .}}

  <main role="main">
    <div class="album py-3 bg-light">
      <div class="container">
        <form class="form-signin" id="frmSettings">
         <div class="alert alert-dark border-bottom"><a href="/member">会员中心</a> > 我的资料</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>
          <div class="py-2">
            <a class="btn btn-danger btn-block" href="/member">返回</a>
          </div>
        </form>
      </div>
    </div>

  </main>
  {{ template "_footer.htm" }}
  <script type="text/javascript">
    var gokeep_token = GetCookie(TokenName())
    if (gokeep_token == null) {
      DirectTo("/member/login");
    }
    $('#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>
  {{ template "_analytics.htm" }}
</body>
</html>
{{ end }}