Files
dufe-net-auto-login/login_self.js
T

566 lines
19 KiB
JavaScript

// 登录管理系统的校验
var loginselfjs_tip1 = "";
var loginselfjs_tip2 = "";
function checkLogin() {
var name = document.getElementById("name");
var password = document.getElementById("password");
// 先清空原先的错误信息
clearError(name);
clearError(password);
var result = true;
if (trim(name.value) == "") {
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
document.getElementById("nameError").style.display="block";
document.getElementById("forErrorMsg").style.display="block";
var loginselfjs_tip3 = document.getElementById("loginselfjs_tip3").value;
document.getElementById("ErrorMessagePanelCommon").innerHTML=loginselfjs_tip3;
result = false;
return result;
} else if (!checkName(name)) {
result = false;
return result;
}
if (password.value == ""||password.value == loginselfjs_tip1||password.value == loginselfjs_tip2) {
document.getElementById("password_text").className="loginInputHKError";
document.getElementById("passwordDiv").className="loginInputHKErrorDiv";
document.getElementById("pwdError").style.display="block";
document.getElementById("forErrorMsg").style.display="block";
var loginselfjs_tip4 = document.getElementById("loginselfjs_tip4").value;
document.getElementById("ErrorMessagePanelCommon").innerHTML=loginselfjs_tip4;
result = false;
return result;
} else if (!checkPassword(password)) {
result = false;
return result;
}
return result;
}
function setScreenWidth(){
var xmlhttp = createXMLHttp();
if (!xmlhttp){
return;
}
var screenWidth = window.screen.availWidth;
var toPath ="getscreenwidthbyajax.jsf?screenWidth="+screenWidth;
xmlhttp.open("GET", toPath, true);
xmlhttp.onreadystatechange = function () {SubmitStateChng(xmlhttp);};
xmlhttp.send(null);
}
function SubmitStateChng(xmlhttp)
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.status == 200) {
// alert(xmlhttp.responseText);
}else {
//alert("HTTP 错误,状态码:" + xmlhttp.status);
}
}else {
//document.getElementById(a).innerHTML="正在获取信息,请稍后....";
}
}
// 校验码的校验
function checkSelf() {
var result = checkLogin();
return result;
}
// 自助用户登录
function selfLogin() {
if (checkSelf()) {
saveUserInfo();
changePasswordValue();
document.loginform.action = "login_judge.jsf";
document.loginform.submit();
}
}
function changePasswordValue(){
//对密码进行判断,看是否要登录时加密。
//将密码进行加密
var password = document.getElementById("password").value;
if(password.length<105){
password = encryptedPassword(password);
}
document.getElementById("password").value=password;
}
// 匿名用户登录
function guestLogin() {
document.loginform.action = "login_guest_judge.jsf";
document.loginform.submit();
}
//直接进入用户注册界面
function toreguserinfo() {
if(document.getElementById("isShowAgreementHidden").value&&(document.getElementById("isShowAgreementHidden").value==true||document.getElementById("isShowAgreementHidden").value=="true")){
$("#procotolContent").html(document.getElementById("agreementInfoHidden").value);
$("#divPop").show();
$("#tipframe").show();
}else{
self.location = '../../userself/web/reguserinfo_guest.jsf';
}
}
function registerNetWorkProtocol(){
self.location = '../../userself/web/reguserinfo_guest.jsf';
}
function closeSubPage(){
$("#divPop").hide();
$("#tipframe").hide();
}
//直接进入找回密码界面
function findPassword(){
self.location ='../../userself/web/password_retrieve.jsf';
}
function isSurroundWithSpace(str) {
if (/^[\x20\u3000]+.*$/.test(str)) {
return true;
}
if (/^.*[\x20\u3000]+$/.test(str)) {
return true;
}
return false;
}
// 校验用户名
function checkName(name) {
document.getElementById("verifyError").style.display="none";//清掉校验码后边的红叉
// var value=trim(name.value);
var value = name.value;
var tempV = value+"";
if($("#_sys_is_international").val()+""=="true"){
while(tempV.indexOf(".") > -1 || tempV.indexOf("@")>-1){
tempV = tempV.replace(".", "").replace("@","");
}
}
if(/[*]/.test(tempV.trim())){
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
document.getElementById("nameError").style.display="block";
document.getElementById("forErrorMsg").style.display="block";
document.getElementById("ErrorMessagePanelCommon").innerHTML="用户名不能包含*号";
return false;
}
if (isSurroundWithSpace(tempV)
|| !tempV
.match(/^[\u4e00-\u9fa5\w\~\!\#\$\^\&\*\(\)\_\+\{\}\|\:\?\`\-\=\[\]\;\,\.\/\x20\u3000]*$/)) {
/*appendErrorMsg(name,
'不能以空格开头或结尾!可以包含任意中英文,字符和数字,但<,>,%,\\,@,\",\'等特殊字符除外!');*/
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
document.getElementById("nameError").style.display="block";
document.getElementById("forErrorMsg").style.display="block";/*<font style='font-size:15px'> ></font>*/
var loginselfjs_tip5 = document.getElementById("loginselfjs_tip5").value;
document.getElementById("ErrorMessagePanelCommon").innerHTML="<a style='cursor:pointer' onmouseover='showMsg()' onmouseout='hideMsg()'>"+loginselfjs_tip5+"<img src='../imgs/downarrow.png' /> </a>";
return false;
}
var loginselfjs_tip6 = document.getElementById("loginselfjs_tip6").value;
if(value.length>32){
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
document.getElementById("nameError").style.display="block";
document.getElementById("forErrorMsg").style.display="block";
document.getElementById("ErrorMessagePanelCommon").innerHTML=loginselfjs_tip6;
return false;
}
var byteLen=0;
for(var i=0;i<value.length;i++){
if(value.charAt(i)>'~')
byteLen=byteLen+2;
else
byteLen++;
}
if(byteLen>32){
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
document.getElementById("nameError").style.display="block";
document.getElementById("forErrorMsg").style.display="block";
document.getElementById("ErrorMessagePanelCommon").innerHTML=loginselfjs_tip6;
return false;
}
return true;
}
function showMsg(){
var showMsgObj=document.getElementById("showMsgDiv").style;
showMsgObj.left=$("#forErrorMsg").offset().left+28;
showMsgObj.top=$("#forErrorMsg").offset().top+30;
var loginselfjs_tip7 = document.getElementById("loginselfjs_tip7").value;
document.getElementById("showMsgDiv").innerHTML=loginselfjs_tip7;
document.getElementById("showMsgDiv").style.display="block";
}
function hideMsg(){
document.getElementById("showMsgDiv").style.display="none";
}
// 校验密码
function checkPassword(password) {
document.getElementById("verifyError").style.display="none";//清掉校验码后边的红叉
var value = password.value;
var byteLen=0;//字节数
for(var i=0;i<value.length;i++){
if(value.charAt(i)>'~')
byteLen=byteLen+2;
else
byteLen++;
}
/*if (byteLen< 3 ||byteLen> 16) {
document.getElementById("passwordDiv").className="loginInputHKErrorDiv";
document.getElementById("pwdError").style.display="block";
document.getElementById("forErrorMsg").style.display="block";
var loginselfjs_tip8 = document.getElementById("loginselfjs_tip8").value;
document.getElementById("ErrorMessagePanelCommon").innerHTML=loginselfjs_tip8;
return false;
}*/
return true;
}
// 清空错误信息
function clearError(errorObj) {
var childNodes = errorObj.parentNode.childNodes;
for (var i = 0; i < childNodes.length; i++) {
var child = childNodes[i];
if (child.id && child.id == "ErrorMessagePanel") {
errorObj.parentNode.removeChild(child);
}
}
document.getElementById("nameError").style.display="none";
document.getElementById("pwdError").style.display="none";
document.getElementById("forErrorMsg").style.display="none";
if(document.getElementById("ErrorMessagePanel")!=null){
document.getElementById("ErrorMessagePanel").innerHTML="";
}
document.getElementById("ErrorMessagePanelCommon").innerHTML="";
}
function findPWD(){
document.loginform.action = "../../userself/web/password_find.jsf";
document.loginform.submit();
}
if(document.addEventListener){//如果是Firefox
document.addEventListener("keypress",fireFoxHandler, true);
}else{
document.attachEvent("onkeypress",ieHandler);
}
function fireFoxHandler(evt){
//alert("firefox");
if(evt.keyCode==13){
saveUserInfo();
selfLogin();//你的代码
}
}
function ieHandler(evt){
//alert("IE");
if(evt.keyCode==13){
saveUserInfo();
selfLogin();//你的代码
}
}
var checked;
function changePic(){
if(checked==false){
document.getElementById('remember').className="becheckedOver";
checked=true;
$("#rememberPwd").attr("checked", true);
}else{
document.getElementById('remember').className="beuncheckedOver";
checked=false;
$("#rememberPwd").attr("checked", false);
}
}
$(document).ready(function(){
document.getElementById("ErrorMessagePanelCommon").innerHTML="";
$("#reguserinfo").bind("click",toreguserinfo);
$("#passwordinfo").bind("click",findPassword);
loginselfjs_tip1 = document.getElementById("loginselfjs_tip1").value.trim();
loginselfjs_tip2 = document.getElementById("loginselfjs_tip2").value.trim();
document.getElementById("password_text").value = loginselfjs_tip2;
$("#password").blur(function(){
if($(this).val()==""){
if($("#havehkPermission").val()+"" == "true"){
$(this).val(loginselfjs_tip1);
}else{
$(this).val(loginselfjs_tip2);
}
if($(this).attr("type") == "password"){
$(this).hide();
$('#password_text').show();
if($("#havehkPermission").val()+"" == "true"){
$('#password_text').val(loginselfjs_tip1);
}else{
$('#password_text').val(loginselfjs_tip2);
}
}
else{
var pass = $('#password_text').val();
if(pass.length<1){
$(this).hide();
$('#password_text').show();
}
}
}else{
document.getElementById("passwordDiv").className="loginInputHKDiv";
}
});
$("#name").blur(function(){
if($(this).val().trim()==""){
$(this).hide();
$('#name_text').removeClass("loginInputHKClicked").addClass("loginInputHK");
$('#name_text').show();
}else{
document.getElementById("passwordDiv").className="loginInputHKDiv";
}
});
$("#password_text").focus(function(){
if(($("#havehkPermission").val()+"" == "true" && $(this).val()==loginselfjs_tip1) ||
($("#havehkPermission").val()+"" != "true" && $(this).val()==loginselfjs_tip2)){
$(this).val("");
if($(this).attr("type")=="text"){
$(this).hide();
$('#password').show();
$('#password').val("");
$('#password').focus();//加上
document.getElementById("passwordDiv").className="loginInputHKClickedDiv";
document.getElementById("pwdError").style.display="none";
if(document.getElementById("nameError").style.display=="block"){//兼容IE10
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
}
}else{
var pass = $('#password').val();
if(pass.length<1){
$(this).hide();
$('#password_text').show();
document.getElementById("passwordDiv").className="loginInputHKClickedDiv";
}
}
}
});
$("#name_text").focus(function(){
$(this).hide();
$('#name').show();
$('#name').val("");
$('#name').focus();//加上
document.getElementById("nameDiv").className="loginInputHKClickedDiv";
document.getElementById("nameError").style.display="none";
if(document.getElementById("nameError").style.display=="block"){//兼容IE10
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
}
});
$("#verify").blur(function(){
if($(this).val().trim()==""){
$(this).hide();
$('#verify_text').removeClass("loginInputHKClicked").addClass("loginInputHK");
$('#verify_text').show();
}
});
var verifyError=document.getElementById("verifyMsg").value;
if(verifyError=="true"){
document.getElementById("verifyError").style.display="block";
var loginselfjs_tip9 = document.getElementById("loginselfjs_tip9").value;
document.getElementById("forErrorMsg").style.display="block";
document.getElementById("ErrorMessagePanelCommon").innerHTML=loginselfjs_tip9;
}
$("#verify_text").focus(function(){
$(this).hide();
$('#verify').show();
$('#verify').val("");
$('#verify').focus();//加上
document.getElementById("verifyDiv").className="loginInputHKClickedDiv";
document.getElementById("verifyError").style.display="none";
if(document.getElementById("verifyError").style.display=="block"){//兼容IE10
document.getElementById("verifyDiv").className="loginInputHKErrorDiv";
}
});
if ($.cookie("rmbUser") == "true") {
$("#rememberPwd").attr("checked", true);
$("#name").val($.cookie("userName"));
$('#password').show();
document.getElementById("passwordDiv").className="loginInputHKDiv";
$('#password_text').hide();
$("#password").val($.cookie("passWord"));
if($.cookie("userName")!='' && $("#logginErrorHidden")[0]!=null){
$.cookie("passWord", $.cookie("oldpassWord"), { expires: 7 ,path:"/"});
if($.cookie("passWord")==null || $.cookie("passWord") == ''){
clearCookie();
}
}
document.getElementById('remember').className="bechecked";
checked=true;
} else{
intervale=setInterval("clear()",10);
$("#rememberPwd").attr("checked", false);
/* document.getElementById("name").value=""; */
document.getElementById('remember').className="beunchecked";
checked=false;
}
if(document.getElementById("name").value==""){
$("#name_text").show();
$("#name").hide();
$("#name_text").focus();
}else{
$("#name_text").hide();
$("#name").show();
$("#name").focus();
$("#name").val($("#name").val());
}
});
function clearCookie(){
$.cookie("rmbUser", "false", { expires: -1 ,path:"/"});
$.cookie("userName", null, { expires: -1 ,path:"/"});
$.cookie("passWord", null, { expires: -1 ,path:"/"});
$.cookie("oldpassWord", null, { expires: -1 ,path:"/"});
$.cookie("rmbUser", "false", { expires: -1 });
$.cookie("userName", null, { expires: -1 });
$.cookie("passWord", null, { expires: -1 });
$.cookie("oldpassWord", null, { expires: -1 });
}
var isfirst=true;
var minHeight=630;
function resize(){
$("#bg").width($("#divTable").width());
$("#bg").height($("#divTable").height());
if(document.body.clientHeight > minHeight){
document.getElementsByTagName("body")[0].style.overflowY="hidden";
var gapPx = 70 + document.body.clientHeight - minHeight;
$("#topGapTd").height(gapPx>110?110:gapPx);
}else{
document.getElementsByTagName("body")[0].style.overflowY="scroll";
$("#topGapTd").height(70);
}
if(document.body.clientWidth > 1180){
document.getElementsByTagName("body")[0].style.overflowX="hidden";
}else{
document.getElementsByTagName("body")[0].style.overflowX="scroll";
}
}
var fornamefirst=true;
function clear(){
if(document.getElementById("name").value!="" && document.getElementById("forName") !=null){
document.getElementById("forName").style.display="none";
}
}
var intervale;
//初始化页面时验证是否记住了密码
//保存用户信息
function saveUserInfo() {
if (document.getElementById("rememberPwd").checked == true) {
var userName = $("#name").val();
var passWord = $("#password").val();
$.cookie("rmbUser", "true", { expires: 7 ,path:"/"}); // 存储一个带7天期限的 cookie
$.cookie("userName", userName, { expires: 7 ,path:"/"}); // 存储一个带7天期限的 cookie
if(passWord.length<105){
passWord = encryptedPassword(passWord);
}
$.cookie("passWord", passWord, { expires: 7 ,path:"/"}); // 存储一个带7天期限的 cookie
}else {
clearCookie();
}
}
function hideErrorImg(){
clearInterval(intervale);
document.getElementById("nameDiv").className="loginInputHKClickedDiv";
document.getElementById("nameError").style.display="none";
}
function hidePwdErrorImg(){
document.getElementById("pwdError").style.display="none";
document.getElementById("passwordDiv").className="loginInputHKClickedDiv";
}
function hideVerifyErrorImg(){
document.getElementById("verifyError").style.display="none";
document.getElementById("verifyDiv").className="loginInputHKClickedDiv";
}
function blurVerifyDiv(){
document.getElementById("verifyDiv").className="loginInputHKDiv";
}
function blurPwdDiv(){
document.getElementById("passwordDiv").className="loginInputHKDiv";
}
function blurNameDiv(){
document.getElementById("nameDiv").className="loginInputHKDiv";
}
function appInfo(){
var browser = {appname: 'unknown', version: 0},
userAgent = window.navigator.userAgent.toLowerCase();
//IE,firefox,opera,chrome,netscape
if ( /(msie|firefox|opera|chrome|netscape)\D+(\d[\d.]*)/.test( userAgent ) ){
browser.appname = RegExp.$1;
browser.version = RegExp.$2;
} else if ( /version\D+(\d[\d.]*).*safari/.test( userAgent ) ){ // safari
browser.appname = 'safari';
browser.version = RegExp.$2;
}
return browser;
}
function forIe7(){
if(document.getElementById("nameError").style.display=="block"){
document.getElementById("nameDiv").className="loginInputHKErrorDiv";
}
}
function mOut(){
if(checked==true){
document.getElementById('remember').className="bechecked";
}else{
document.getElementById('remember').className="beunchecked";
}
}
function mOver(){
if(checked==true){
document.getElementById('remember').className="becheckedOver";
}else{
document.getElementById('remember').className="beuncheckedOver";
}
}
function faq(){
var pra = "directories=0,fullscreen=0,top=0,left=0," +
"location=0,menubar=0,status=0,toolbar=0,width="+window.screen.availWidth+",height="+(window.screen.availHeight-80);
window.open('../../repairself/web/repairreportfaqselfnologin_list.jsf', "FAQ", pra);
}
//对密码进行加密
function encryptedPassword (password){
//老的加密算法有问题,使用新的实现方法
var key = document.getElementById("publicKey").value;
var split = key.split("&");
var publicKeyExponent = split[0];
var publicKeyModulus =split[1];
RSAUtils.setMaxDigits(200);
var key = new RSAUtils.getKeyPair(publicKeyExponent, "", publicKeyModulus);
var passwordEncry = RSAUtils.encryptedString(key,password.split("").reverse().join(""));//这里要对字符串进行反转,否则解密的密码是反的
return passwordEncry;
}