算法评测平台前端。
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.

116 lines
4.1 KiB

<% this.title = '注册' %>
7 years ago
<% this.noPreserveUrl = true; %>
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="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="<%- lib('blueimp-md5/2.10.0/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("注册成功!");
6 years ago
window.location.href = location.protocol + '//' + location.host + <%- JSON.stringify(req.query.url || '/') %>;
8 years ago
}
function mail_required() {
alert("注册确认邮件已经发送到您的邮箱的垃圾箱,点击邮件内的链接即可完成注册。");
var s = $("#email").val();
var mailWebsite = 'https://mail.' + s.substring(s.indexOf('@') + 1, s.length);
if (mailWebsite === 'https://mail.gmail.com') mailWebsite = 'https://mail.google.com';
window.location.href = mailWebsite;
}
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(),
prevUrl: <%- JSON.stringify(req.query.url || '/') %>
8 years ago
},
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;
case 2010:
8 years ago
show_error("验证邮件发送失败:\n" + data.message);
break;
8 years ago
case 1:
success();
break;
case 2:
mail_required();
break;
8 years ago
default:
show_error("未知错误:" + JSON.stringify(data));
8 years ago
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 %>