<!doctype html>
[#escape x as (x)!?html]
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>用户登录 - ${site.title}</title>
  <meta name="_csrf" content="${_csrf.token}"/>
  <meta name="_csrf_header" content="${_csrf.headerName}"/>
  [#include 'includes_meta.html'/]
  [#include 'includes_css.html'/]
  [#include 'includes_js.html'/]
  [#include 'includes_js_validation.html'/]
  <script src="${files}/vendor/crypto-js/crypto-js.min.js"></script>
  <script src="${files}/vendor/sm-crypto/dist/sm2.js"></script>
</head>
<body class="bg-light">
<div class="container my-3 my-md-4 my-lg-5">
  <div class="row justify-content-center">
    <div class="col col-md-6 col-lg-5 col-xl-5 reg-box">
      <h3 class="reg-logo text-center">
        <a href="/"><b>UJCMS</b></a> <span>注册新用户</span>
      </h3>
      <div class="mt-3 text-center">欢迎您: ${(Session.oauthToken.nickname)!'NULL'}</div>
      <div class="reg-box-body rounded p-4 mt-4" style="background-color:#fff;border:1px solid #ccc;">
        <form class="mb-2" id="validForm" action="${def}/oauth/register" method="post">
          <div class="form-group">
            <label class="sr-only" for="username">用户名</label>
            <input type="text" class="form-control" id="username" name="username" value="${(Session.oauthToken.nickname)!'NULL'}" placeholder="用户名" title="请输入用户名" required
                   maxlength="${config.register.usernameMaxLength}"
                   data-rule-minlength="${config.register.usernameMinLength}" data-msg-minlength="用户名不能少于 ${config.register.usernameMinLength} 个字符"
                   data-rule-pattern="${config.register.usernameRegex}" data-msg-pattern="用户名只支持 字母、数字、汉字、下划线、中划线、点号"
                   data-rule-remote="${api}/user/username-not-exist" data-msg-remote="用户名已存在">
            <!--<small class="form-text text-muted">4~18个字符，可使用字母、数字、下划线</small>-->
          </div>
          [#-- 手机号码验证 --]
          [#if config.register.verifyMode = 4]
            <div class="form-group">
              <label class="sr-only" for="mobile">手机号码</label>
              <input type="text" class="form-control" id="mobile" name="mobile" placeholder="手机号码" autocomplete="off" required title="请填写手机号码"
                     data-rule-pattern="^1\d{10}$" data-msg-pattern="请填写有效的手机号码" data-rule-remote="${api}/user/mobile-not-exist" data-msg-remote="手机号码已存在">
            </div>
            <div class="form-group">
              <label class="sr-only" for="mobileMessageValue">短信验证码</label>
              <div class="input-group">
                <input type="text" class="form-control" id="mobileMessageValue" name="mobileMessageValue" placeholder="短信验证码" autocomplete="off" required title="请填写短信验证码"
                       data-msg-remote="短信验证码不正确">
                <input type="hidden" id="mobileMessageId" name="mobileMessageId">
                <span class="input-group-append"><button class="btn btn-secondary" id="mobileMessageButton" type="button">获取短信验证码</button></span>
              </div>
            </div>
          [/#if]
          <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}">
          <button type="submit" class="btn btn-primary btn-block">注册</button>

          <p class="text-center text-muted small mt-2">
            登录或注册代表您同意 <a href="#">服务条款</a>
          </p>
        </form>
      </div>
    </div>
  </div>
</div>

[#include 'includes_message_box.html'/]
[#include 'includes_short_message.html'/]

<script>
  var publicKey;
  axios.get('${api}/env/client-public-key').then(function (response) {
    publicKey = response.data;
  });

  function sm2Encrypt(message) {
    return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse('04' + sm2.doEncrypt(message, publicKey)));
  }

  $(function () {
    var validator = $('#validForm').validate({
      rules: {
        mobileMessageValue: {
          remote: {
            url: '${api}/sms/mobile/try', data: {
              mobileMessageId: function () {
                return $('#mobileMessageId').val();
              },
              mobile: function () {
                return $('#mobile').val();
              }
            }
          }
        }
      }
    });
    $('#emailMessageButton').click(function () {
      sendEmailMessage(validator, $('#email'), $('#emailMessageId'), $(this), 6);
    });
    $('#mobileMessageButton').click(function () {
      sendMobileMessage(validator, $('#mobile'), $('#mobileMessageId'), $(this), 5);
    });
  });

</script>
</body>
</html>
[/#escape]
