|
|
|
<% this.title = '注册' %>
|
|
|
|
<% include header %>
|
|
|
|
<h1>注册</h1>
|
|
|
|
<div class="padding">
|
|
|
|
<div class="ui error message" id="error" data-am-alert hidden>
|
|
|
|
<p id="error_info"></p>
|
|
|
|
</div>
|
|
|
|
<form class="ui form">
|
|
|
|
<div class="field">
|
|
|
|
<label for="username">用户名</label>
|
|
|
|
<input type="text" placeholder="" id="username">
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
|
|
|
<label for="email">邮箱</label>
|
|
|
|
<input type="email" placeholder="" id="email">
|
|
|
|
</div>
|
|
|
|
<!--div class="field">
|
|
|
|
<label for="email">邀请码</label>
|
|
|
|
<input type="text" placeholder="Invitation code" id="invitation_code">
|
|
|
|
</div-->
|
|
|
|
<div class="two fields">
|
|
|
|
<div class="field">
|
|
|
|
<label class="ui header">密码</label>
|
|
|
|
<input type="password" placeholder="" id="password1">
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
|
|
|
<label class="ui header">确认密码</label>
|
|
|
|
<input type="password" placeholder="" id="password2">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<a id="sign_up" class="ui button" onclick="submit()">注册</a>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<script src="//cdn.bootcss.com/blueimp-md5/2.5.0/js/md5.min.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
function show_error(error) {
|
|
|
|
$("#error_info").text(error);
|
|
|
|
$("#error").show();
|
|
|
|
}
|
|
|
|
function success() {
|
|
|
|
alert("注册成功!");
|
|
|
|
window.location.href = <%- JSON.stringify(req.query.url || '/') %>;
|
|
|
|
}
|
|
|
|
function submit() {
|
|
|
|
if ($("#password1").val() != $("#password2").val()) {
|
|
|
|
show_error("两次输入的密码不一致");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
password = md5($("#password1").val() + "syzoj2_xxx")
|
|
|
|
$("#sign_up").addClass("loading");
|
|
|
|
$.ajax({
|
|
|
|
url: '/api/sign_up',
|
|
|
|
type: 'POST',
|
|
|
|
async: true,
|
|
|
|
data: {
|
|
|
|
username: $("#username").val(),
|
|
|
|
password: password,
|
|
|
|
email: $("#email").val()
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
error_code = data.error_code;
|
|
|
|
switch(error_code){
|
|
|
|
case 2001:
|
|
|
|
show_error("服务器未收到数据");
|
|
|
|
break;
|
|
|
|
case 2005:
|
|
|
|
case 2002:
|
|
|
|
show_error("用户名需要大于 3 个字符小于 16 个字符,仅允许字母数字和下划线");
|
|
|
|
break;
|
|
|
|
case 2007:
|
|
|
|
case 2003:
|
|
|
|
show_error("密码不得为空");
|
|
|
|
break;
|
|
|
|
case 2004:
|
|
|
|
case 2006:
|
|
|
|
show_error("请输入正确的邮箱");
|
|
|
|
break;
|
|
|
|
case 2008:
|
|
|
|
show_error("已经有人用过这个用户名了");
|
|
|
|
break;
|
|
|
|
case 2009:
|
|
|
|
show_error("邀请码错误,请联系管理员索要");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
success();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
show_error("未知错误");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$("#sign_up").removeClass("loading");
|
|
|
|
},
|
|
|
|
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
alert(XMLHttpRequest.responseText);
|
|
|
|
show_error("未知错误");
|
|
|
|
$("#sign_up").removeClass("loading");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<% include footer %>
|