2018-07-26 03:51:45 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* login.html
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-11-27 06:37:50 +00:00
|
|
|
|
$(function() {
|
|
|
|
|
|
// 回车键快捷操作
|
|
|
|
|
|
$("body").keypress(function(e) {
|
|
|
|
|
|
var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
|
|
|
|
|
|
if (keyCode == 13) {
|
|
|
|
|
|
var g = $("#loginBtn").click();
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-04-25 01:32:44 +00:00
|
|
|
|
$("#vercodebox").html("");
|
|
|
|
|
|
$("#vercodebox").removeClass("show");
|
|
|
|
|
|
$("#vercodebox").addClass("hidden");
|
2018-11-27 06:37:50 +00:00
|
|
|
|
// 打开页面自动聚焦账户输入框
|
|
|
|
|
|
$("#accountid").focus();
|
2019-10-08 02:16:07 +00:00
|
|
|
|
// 询问是否可以显示注册按钮
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
|
type : "POST",
|
|
|
|
|
|
dataType : "text",
|
|
|
|
|
|
data : {},
|
|
|
|
|
|
url : "homeController/askForAllowSignUpOrNot.ajax",
|
|
|
|
|
|
success : function(result) {
|
|
|
|
|
|
if (result == "true") {
|
|
|
|
|
|
$("#signupBox").removeClass("hidden");
|
|
|
|
|
|
$("#signupBox").addClass("show");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
error : function() {
|
|
|
|
|
|
alert("错误:无法连接到kiftd服务器,请检查您的网络连接或查看服务器运行状态。");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2018-11-27 06:37:50 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
2018-07-26 03:51:45 +00:00
|
|
|
|
function dologin() {
|
|
|
|
|
|
var accountId = $("#accountid").val();
|
|
|
|
|
|
var accountPwd = $("#accountpwd").val();
|
|
|
|
|
|
var check = "y";
|
|
|
|
|
|
if (accountId.length == 0) {
|
|
|
|
|
|
$("#accountidbox").addClass("has-error");
|
|
|
|
|
|
check = "n"
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$("#accountidbox").removeClass("has-error");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (accountPwd.length == 0) {
|
|
|
|
|
|
$("#accountpwdbox").addClass("has-error");
|
|
|
|
|
|
check = "n"
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$("#accountpwdbox").removeClass("has-error");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (check == "y") {
|
2020-02-09 01:07:11 +00:00
|
|
|
|
startLogin();
|
2018-07-26 03:51:45 +00:00
|
|
|
|
$.ajax({
|
|
|
|
|
|
type : "POST",
|
|
|
|
|
|
dataType : "text",
|
|
|
|
|
|
url : "homeController/getPublicKey.ajax",
|
|
|
|
|
|
data : {},
|
|
|
|
|
|
success : function(result) {
|
2018-11-27 06:37:50 +00:00
|
|
|
|
var publicKeyInfo = eval("(" + result + ")");
|
2018-07-26 03:51:45 +00:00
|
|
|
|
var loginInfo = '{accountId:"' + accountId + '",accountPwd:"'
|
|
|
|
|
|
+ accountPwd + '",time:"' + publicKeyInfo.time + '"}';
|
|
|
|
|
|
var encrypt = new JSEncrypt();// 加密插件对象
|
|
|
|
|
|
encrypt.setPublicKey(publicKeyInfo.publicKey);// 设置公钥
|
|
|
|
|
|
var encrypted = encrypt.encrypt(loginInfo);// 进行加密
|
|
|
|
|
|
sendLoginInfo(encrypted);
|
|
|
|
|
|
},
|
|
|
|
|
|
error : function() {
|
2020-02-09 01:07:11 +00:00
|
|
|
|
showAlert("提示:登录请求失败,请检查网络或服务器运行状态");
|
2018-07-26 03:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sendLoginInfo(encrypted) {
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
|
type : "POST",
|
|
|
|
|
|
dataType : "text",
|
|
|
|
|
|
url : "homeController/doLogin.ajax",
|
|
|
|
|
|
data : {
|
2019-04-25 01:32:44 +00:00
|
|
|
|
encrypted : encrypted,
|
|
|
|
|
|
vercode : $("#vercode").val()
|
2018-07-26 03:51:45 +00:00
|
|
|
|
},
|
|
|
|
|
|
success : function(result) {
|
|
|
|
|
|
$("#alertbox").removeClass("alert");
|
|
|
|
|
|
$("#alertbox").removeClass("alert-danger");
|
|
|
|
|
|
$("#alertbox").text("");
|
2019-04-25 01:32:44 +00:00
|
|
|
|
$("#vercodebox").html("");
|
|
|
|
|
|
$("#vercodebox").removeClass("show");
|
|
|
|
|
|
$("#vercodebox").addClass("hidden");
|
|
|
|
|
|
switch (result) {
|
|
|
|
|
|
case "permitlogin":
|
2020-02-09 01:07:11 +00:00
|
|
|
|
finishLogin();
|
2018-07-26 03:51:45 +00:00
|
|
|
|
$("#accountidbox").removeClass("has-error");
|
|
|
|
|
|
$("#accountpwdbox").removeClass("has-error");
|
2019-10-08 02:16:07 +00:00
|
|
|
|
window.location.href = "/home.html";
|
2019-04-25 01:32:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "accountnotfound":
|
2018-07-26 03:51:45 +00:00
|
|
|
|
$("#accountidbox").addClass("has-error");
|
|
|
|
|
|
$("#accountpwdbox").removeClass("has-error");
|
2020-02-09 01:07:11 +00:00
|
|
|
|
showAlert("提示:登录失败,账户不存在或未设置");
|
2019-04-25 01:32:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "accountpwderror":
|
2018-07-26 03:51:45 +00:00
|
|
|
|
$("#accountpwdbox").addClass("has-error");
|
|
|
|
|
|
$("#accountidbox").removeClass("has-error");
|
2020-02-09 01:07:11 +00:00
|
|
|
|
showAlert("提示:登录失败,密码错误或未设置");
|
2019-04-25 01:32:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case "needsubmitvercode":
|
2020-02-09 01:07:11 +00:00
|
|
|
|
finishLogin();
|
2019-04-25 01:32:44 +00:00
|
|
|
|
$("#vercodebox").html("<label id='vercodetitle' class='col-sm-6'><img id='showvercode' class='vercodeimg' alt='点击获取验证码' src='homeController/getNewVerCode.do?s="+(new Date()).getTime()+"' onclick='getNewVerCode()'></label><div class='col-sm-6'><input type='text' class='form-control' id='vercode' placeholder='验证码……'></div>");
|
|
|
|
|
|
$("#vercodebox").removeClass("hidden");
|
|
|
|
|
|
$("#vercodebox").addClass("show");
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "error":
|
2020-02-09 01:07:11 +00:00
|
|
|
|
showAlert("提示:登录失败,登录请求无法通过效验(可能是请求耗时过长导致的)");
|
2019-04-25 01:32:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2020-02-09 01:07:11 +00:00
|
|
|
|
showAlert("提示:无法登录,未知错误");
|
2019-04-25 01:32:44 +00:00
|
|
|
|
break;
|
2018-07-26 03:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
error : function() {
|
2020-02-09 01:07:11 +00:00
|
|
|
|
showAlert("提示:登录请求失败,请检查网络或服务器运行状态");
|
2018-07-26 03:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-04-25 01:32:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取一个新的验证码
|
|
|
|
|
|
function getNewVerCode(){
|
|
|
|
|
|
$("#showvercode").attr("src","homeController/getNewVerCode.do?s="+(new Date()).getTime());
|
2020-02-09 01:07:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function showAlert(text){
|
|
|
|
|
|
finishLogin();
|
|
|
|
|
|
$("#alertbox").addClass("alert");
|
|
|
|
|
|
$("#alertbox").addClass("alert-danger");
|
|
|
|
|
|
$("#alertbox").text(text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function startLogin(){
|
|
|
|
|
|
$("#loginBtn").attr('disabled','disabled');
|
|
|
|
|
|
$("#accountid").attr('disabled','disabled');
|
|
|
|
|
|
$("#accountpwd").attr('disabled','disabled');
|
|
|
|
|
|
$("#vercode").attr('disabled','disabled');
|
|
|
|
|
|
$("#loginBtn").val('正在登录...');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function finishLogin(){
|
|
|
|
|
|
$("#loginBtn").removeAttr('disabled');
|
|
|
|
|
|
$("#accountid").removeAttr('disabled');
|
|
|
|
|
|
$("#accountpwd").removeAttr('disabled');
|
|
|
|
|
|
$("#vercode").removeAttr('disabled');
|
|
|
|
|
|
$("#loginBtn").val('登录');
|
2018-07-26 03:51:45 +00:00
|
|
|
|
}
|