算法评测平台前端。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.6 KiB

<% this.title = '注册' %>
8 years ago
<% include header %>
<div class="padding">
<h1>注册</h1>
<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">
8 years ago
</div>
<div class="field">
<label for="email">邮箱</label>
<input type="email" placeholder="" id="email">
8 years ago
</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">
8 years ago
</div>
<div class="field">
<label class="ui header">确认密码</label>
<input type="password" placeholder="" id="password2">
8 years ago
</div>
</div>
<a id="sign_up" class="ui button" href="javascript:submit();">注册</a>
8 years ago
</form>
</div>
<script src="/libs/blueimp-md5/js/md5.min.js"></script>
8 years ago
<script type="text/javascript">
function show_error(error) {
8 years ago
$("#error_info").text(error);
$("#error").show();
}
function success() {
alert("注册成功!");
window.location.href = <%- JSON.stringify(req.query.url || '/') %>;
8 years ago
}
function submit() {
if ($("#password1").val() != $("#password2").val()) {
show_error("两次输入的密码不一致");
8 years ago
return;
}
password = md5($("#password1").val() + "syzoj2_xxx")
$("#sign_up").addClass("loading");
8 years ago
$.ajax({
url: '/api/sign_up',
type: 'POST',
async: true,
8 years ago
data: {
username: $("#username").val(),
password: password,
email: $("#email").val()
},
success: function(data) {
error_code = data.error_code;
8 years ago
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;
8 years ago
case 1:
success();
break;
default:
show_error("未知错误");
break;
}
$("#sign_up").removeClass("loading");
8 years ago
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
8 years ago
alert(XMLHttpRequest.responseText);
show_error("未知错误");
$("#sign_up").removeClass("loading");
8 years ago
}
});
}
</script>
<% include footer %>