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.
96 lines
2.8 KiB
96 lines
2.8 KiB
<% this.title = '登录' %> |
|
<% 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"> |
|
登陆 |
|
</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> |
|
<input name="email" placeholder="用户名" type="text" id="username" onkeydown="key_login()"> |
|
</div> |
|
</div> |
|
<div class="field"> |
|
<div class="ui left icon input"> |
|
<i class="lock icon"></i> |
|
<input name="password" placeholder="密码" type="password" id="password" onkeydown="key_login()"> |
|
</div> |
|
</div> |
|
<div class="ui fluid large submit button" id="login">登录</div> |
|
</div> |
|
|
|
<div class="ui error message"></div> |
|
|
|
</form> |
|
|
|
<div class="ui message"> |
|
新用户? <a href="/sign_up">注册</a> |
|
</div> |
|
</div> |
|
</div> |
|
</div> |
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/blueimp-md5/2.5.0/js/md5.min.js"></script> |
|
<script type="text/javascript"> |
|
function key_login() { |
|
if (event.keyCode == 13) { |
|
login(); |
|
} |
|
} |
|
function show_error(error) { |
|
$("#error").text(error); |
|
$("#error").show(); |
|
} |
|
function success(session_id) { |
|
window.location.href = "/"; |
|
} |
|
function login() { |
|
password = md5($("#password").val() + "syzoj2_xxx"); |
|
$("#login").addClass("loading"); |
|
$.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) { |
|
case 1001: |
|
show_error("No such user."); |
|
break; |
|
case 1002: |
|
show_error("Wrong password."); |
|
break; |
|
case 1: |
|
success(data.session_id); |
|
break; |
|
default: |
|
show_error("Unknown error."); |
|
break; |
|
} |
|
$("#login").text("Login"); |
|
$("#login").removeClass("loading"); |
|
}, |
|
error: function(XMLHttpRequest, textStatus, errorThrown) { |
|
alert(XMLHttpRequest.responseText); |
|
show_error("未知错误"); |
|
$("#login").text("Login"); |
|
} |
|
}); |
|
} |
|
$(document).ready(function() { |
|
$("#login").click(function() { |
|
login(); |
|
}); |
|
}); |
|
</script> |
|
<% include footer %>
|
|
|