<!DOCTYPE html>
<html>
  <head>
    <title>Admin Login</title>
    <!-- Bootstrap -->
    <link href="<?= base_url().'/'; ?>theme/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="<?= base_url().'/'; ?>theme/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
    <link href="<?= base_url().'/'; ?>theme/assets/styles.css" rel="stylesheet" media="screen">
    <script src="<?= base_url().'/'; ?>js/md5.min.js"></script>
  </head>
  <body id="login">
    <div class="container">

      <form class="form-signin">
        <h2 class="form-signin-heading">请注册...</h2>
        <input type="text" class="input-block-level" placeholder="用户名" id="username">
        <input type="text" class="input-block-level" placeholder="昵称" id="nick">
        <input type="password" class="input-block-level" placeholder="密码" id="password">
        <input type="password" class="input-block-level" placeholder="确认密码" id="repassword">
        <button class="btn btn-large btn-primary" type="button" onclick="register()">注 册</button>
        <a href="<?= base_url().'/'; ?>sign/loginPage" style="margin:12px;float:right;">已有账号，去登录?</a>
      </form>

    </div> <!-- /container -->
    <script src="<?= base_url().'/'; ?>theme/vendors/jquery-1.9.1.min.js"></script>
    <script src="<?= base_url().'/'; ?>theme/bootstrap/js/bootstrap.min.js"></script>

<script>
/* *************************************
 *       注册新用户
************************************** */
function register(){
    var username = $("#username").val();
    var nick = $("#nick").val();
    var password = $("#password").val();
    var repassword = $("#repassword").val();

    if(password == "" || username == ""){
        alert("用户名或密码不能为空！");
    }else if(password != repassword){
        alert("密码不一致！");
    }else{
        password = md5(password);
        var host = window.location.host;
        var url = "http://" + host + "/signCtr/register"
        var postData = {};
        postData["username"] = username;
        postData["nick"] = nick;
        postData["password"] = password;
        $.ajax({
            url: url,
            data: JSON.stringify(postData),
            type: "POST",
            dataType: "json",
            contentType:"application/json",
            success: function(data) {
                if(data.status == "200"){
                    alert("注册成功，去登录！");
                    window.location.href = "http://" + host + "/sign/loginPage";
                }else{
                    alert(data.message);
                }
            }
        });
    }
}

</script>
  </body>
</html>