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

97 lines
2.8 KiB

<% this.title = '登录' %>
8 years ago
<% include header %>
<div class="ui error message" id="error" hidden></div>
<div class="ui middle aligned center aligned grid">
<div class="row">
<div class="column" style="max-width: 450px">
<h2 class="ui image header">
<div class="content">
登录
8 years ago
</div>
</h2>
<form class="ui large form">
<div class="ui existing segment">
<div class="field">
<div class="ui left icon input">
<i class="user icon"></i>
8 years ago
<input name="email" placeholder="用户名" type="text" id="username" onkeydown="key_login(event)">
8 years ago
</div>
</div>
<div class="field">
<div class="ui left icon input">
<i class="lock icon"></i>
8 years ago
<input name="password" placeholder="密码" type="password" id="password" onkeydown="key_login(event)">
8 years ago
</div>
</div>
<div class="ui fluid large submit button" id="login">登录</div>
</div>
8 years ago
<div class="ui error message"></div>
</form>
<div class="ui message">
新用户? <a href="/sign_up">注册</a>
</div>
8 years ago
</div>
</div>
8 years ago
</div>
<script src="/libs/blueimp-md5/js/md5.min.js"></script>
8 years ago
<script type="text/javascript">
8 years ago
function key_login(event) {
if (event.keyCode == 13) {
login();
}
8 years ago
}
function show_error(error) {
$("#error").text(error);
8 years ago
$("#error").show();
}
function success(session_id) {
window.location.href = <%- JSON.stringify(req.query.url || '/') %>;
8 years ago
}
function login() {
password = md5($("#password").val() + "syzoj2_xxx");
$("#login").addClass("loading");
8 years ago
$.ajax({
url: "/api/login",
type: 'POST',
data: {
"username": $("#username").val(),
"password": password
},
async: true,
success: function(data) {
error_code = data.error_code;
switch (error_code) {
8 years ago
case 1001:
8 years ago
show_error("用户不存在");
8 years ago
break;
case 1002:
8 years ago
show_error("密码错误");
8 years ago
break;
case 1:
success(data.session_id);
8 years ago
return;
8 years ago
default:
8 years ago
show_error("未知错误");
8 years ago
break;
}
8 years ago
$("#login").text("登录");
$("#login").removeClass("loading");
8 years ago
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
8 years ago
alert(XMLHttpRequest.responseText);
show_error("未知错误");
8 years ago
$("#login").text("登录");
8 years ago
}
});
}
$(document).ready(function() {
$("#login").click(function() {
8 years ago
login();
});
});
</script>
<% include footer %>