$(function(){ //记住密码 var username = $.cookies.get("loginId"); var password = $.cookies.get("pwd"); var auto = $.cookies.get("auto"); erroNum = jQuery.cookies.get('LOGIN_ERROR'); var JSessionId = $.cookies.get("JSESSIONID"); if(username!=""&&username!="undefined"&&username!=null&&username!="null"){ $("#loginId").val(username); } if(password!="" && password!="undefined" && auto=="yes"){ $("#passwd").val(password); $("#auto").prop('checked',true); }else{ $("#auto").prop('checked',false); } //验证码 reloadcode(); erroNum = jQuery.cookies.get('LOGIN_ERROR'); /* 密码错误三次以上,显示验证码start **/ if(erroNum==null) { erroNum = 0; } }) function getRootPath() { var strFullPath = window.document.location.href; var strPath = window.document.location.pathname; var pos = strFullPath.indexOf(strPath); var prePath = strFullPath.substring(0, pos); var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1); return (prePath + postPath); } // md5 begin var hex_chr = '0123456789abcdef'; function rhex(num) { str = ""; for (j = 0; j <= 3; j++) str += hex_chr.charAt((num >> (j * 8 + 4)) & 0x0F) + hex_chr.charAt((num >> (j * 8)) & 0x0F); return str; } function str2blks_MD5(str) { nblk = ((str.length + 8) >> 6) + 1; blks = new Array(nblk * 16); for (i = 0; i < nblk * 16; i++) blks[i] = 0; for (i = 0; i < str.length; i++) blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8); blks[i >> 2] |= 0x80 << ((i % 4) * 8); blks[nblk * 16 - 2] = str.length * 8; return blks; } function add(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); } function rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); } function cmn(q, a, b, x, s, t) { return add(rol(add(add(a, q), add(x, t)), s), b); } function ff(a, b, c, d, x, s, t) { return cmn((b & c) | ((~b) & d), a, b, x, s, t); } function gg(a, b, c, d, x, s, t) { return cmn((b & d) | (c & (~d)), a, b, x, s, t); } function hh(a, b, c, d, x, s, t) { return cmn(b ^ c ^ d, a, b, x, s, t); } function ii(a, b, c, d, x, s, t) { return cmn(c ^ (b | (~d)), a, b, x, s, t); } function MD5(str) { if (str.length == 0) { return str; } x = str2blks_MD5(str); var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; for (i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; a = ff(a, b, c, d, x[i + 0], 7, -680876936); d = ff(d, a, b, c, x[i + 1], 12, -389564586); c = ff(c, d, a, b, x[i + 2], 17, 606105819); b = ff(b, c, d, a, x[i + 3], 22, -1044525330); a = ff(a, b, c, d, x[i + 4], 7, -176418897); d = ff(d, a, b, c, x[i + 5], 12, 1200080426); c = ff(c, d, a, b, x[i + 6], 17, -1473231341); b = ff(b, c, d, a, x[i + 7], 22, -45705983); a = ff(a, b, c, d, x[i + 8], 7, 1770035416); d = ff(d, a, b, c, x[i + 9], 12, -1958414417); c = ff(c, d, a, b, x[i + 10], 17, -42063); b = ff(b, c, d, a, x[i + 11], 22, -1990404162); a = ff(a, b, c, d, x[i + 12], 7, 1804603682); d = ff(d, a, b, c, x[i + 13], 12, -40341101); c = ff(c, d, a, b, x[i + 14], 17, -1502002290); b = ff(b, c, d, a, x[i + 15], 22, 1236535329); a = gg(a, b, c, d, x[i + 1], 5, -165796510); d = gg(d, a, b, c, x[i + 6], 9, -1069501632); c = gg(c, d, a, b, x[i + 11], 14, 643717713); b = gg(b, c, d, a, x[i + 0], 20, -373897302); a = gg(a, b, c, d, x[i + 5], 5, -701558691); d = gg(d, a, b, c, x[i + 10], 9, 38016083); c = gg(c, d, a, b, x[i + 15], 14, -660478335); b = gg(b, c, d, a, x[i + 4], 20, -405537848); a = gg(a, b, c, d, x[i + 9], 5, 568446438); d = gg(d, a, b, c, x[i + 14], 9, -1019803690); c = gg(c, d, a, b, x[i + 3], 14, -187363961); b = gg(b, c, d, a, x[i + 8], 20, 1163531501); a = gg(a, b, c, d, x[i + 13], 5, -1444681467); d = gg(d, a, b, c, x[i + 2], 9, -51403784); c = gg(c, d, a, b, x[i + 7], 14, 1735328473); b = gg(b, c, d, a, x[i + 12], 20, -1926607734); a = hh(a, b, c, d, x[i + 5], 4, -378558); d = hh(d, a, b, c, x[i + 8], 11, -2022574463); c = hh(c, d, a, b, x[i + 11], 16, 1839030562); b = hh(b, c, d, a, x[i + 14], 23, -35309556); a = hh(a, b, c, d, x[i + 1], 4, -1530992060); d = hh(d, a, b, c, x[i + 4], 11, 1272893353); c = hh(c, d, a, b, x[i + 7], 16, -155497632); b = hh(b, c, d, a, x[i + 10], 23, -1094730640); a = hh(a, b, c, d, x[i + 13], 4, 681279174); d = hh(d, a, b, c, x[i + 0], 11, -358537222); c = hh(c, d, a, b, x[i + 3], 16, -722521979); b = hh(b, c, d, a, x[i + 6], 23, 76029189); a = hh(a, b, c, d, x[i + 9], 4, -640364487); d = hh(d, a, b, c, x[i + 12], 11, -421815835); c = hh(c, d, a, b, x[i + 15], 16, 530742520); b = hh(b, c, d, a, x[i + 2], 23, -995338651); a = ii(a, b, c, d, x[i + 0], 6, -198630844); d = ii(d, a, b, c, x[i + 7], 10, 1126891415); c = ii(c, d, a, b, x[i + 14], 15, -1416354905); b = ii(b, c, d, a, x[i + 5], 21, -57434055); a = ii(a, b, c, d, x[i + 12], 6, 1700485571); d = ii(d, a, b, c, x[i + 3], 10, -1894986606); c = ii(c, d, a, b, x[i + 10], 15, -1051523); b = ii(b, c, d, a, x[i + 1], 21, -2054922799); a = ii(a, b, c, d, x[i + 8], 6, 1873313359); d = ii(d, a, b, c, x[i + 15], 10, -30611744); c = ii(c, d, a, b, x[i + 6], 15, -1560198380); b = ii(b, c, d, a, x[i + 13], 21, 1309151649); a = ii(a, b, c, d, x[i + 4], 6, -145523070); d = ii(d, a, b, c, x[i + 11], 10, -1120210379); c = ii(c, d, a, b, x[i + 2], 15, 718787259); b = ii(b, c, d, a, x[i + 9], 21, -343485551); a = add(a, olda); b = add(b, oldb); c = add(c, oldc); d = add(d, oldd); } return rhex(a) + rhex(b) + rhex(c) + rhex(d); } // md5 end /* pwd level start */ //以下用于检查密码强度 // CharMode函数 // 测试某个字符是属于哪一类. function CharMode(iN) { if (iN >= 48 && iN <= 57) // 数字 return 1; if (iN >= 65 && iN <= 90) // 大写字母 return 2; if (iN >= 97 && iN <= 122) // 小写 return 4; else return 8; // 特殊字符 } // bitTotal函数 // 计算出当前密码当中一共有多少种模式 function bitTotal(num) { modes = 0; for (i = 0; i < 4; i++) { if (num & 1) modes++; num >>>= 1; } return modes; } // checkStrong函数 // 返回密码的强度级别 function checkPasswdRate(sPW) { if (sPW.length <= 5) return 0; // 密码太短 Modes = 0; for (i = 0; i < sPW.length; i++) { // 测试每一个字符的类别并统计一共有多少种模式. Modes |= CharMode(sPW.charCodeAt(i)); } return bitTotal(Modes); } /* pwd level end */ /**/ /* 为IE6 IE7 IE8增加document.getElementsByClassName函数 */ /MSIE\s*(\d+)/i.test(navigator.userAgent); var isIE = parseInt(RegExp.$1 ? RegExp.$1 : 0); if (isIE > 0 && isIE < 9) { document.getElementsByClassName = function (cls) { var els = this.getElementsByTagName('*'); var ell = els.length; var elements = []; for (var n = 0; n < ell; n++) { var oCls = els[n].className || ''; if (oCls.indexOf(cls) < 0) continue; oCls = oCls.split(/\s+/); var oCll = oCls.length; for (var j = 0; j < oCll; j++) { if (cls == oCls[j]) { elements.push(els[n]); break; } } } return elements; } } /**/ /* 使用appendChild创建结点 */ function CreateNode(str, type, css) { // 创建新节点 var NewDiv = document.createElement(type); if (css != undefined && css != null && css != '') { NewDiv.className = css; } // 为创建的节点内加入的内容 var NewText = document.createTextNode(str); // 追加一个新的子结点 NewDiv.appendChild(NewText); // 返回新创建结点数据 return NewDiv; } //清空某节点下的子节点 function clearNode(nodeId) { var node = document.getElementById(nodeId); while (node.childNodes.length != 0) { node.style.display = "none"; node.removeChild(node.firstChild); } var errorTip; try { errorTip = document.getElementsByClassName("errortip"); } catch (e) { } if (errorTip != undefined && errorTip.length > 0) { for (var i = 0; i < errorTip.length; i++) { if (errorTip[i].childNodes.length != 0) { errorTip[i].style.display = "none"; errorTip[i].removeChild(errorTip[i].firstChild); } } } } // 向指定结点内插入新结点函数 function insertWithin(nodeId, str, css) { // 指定结点 id clearNode(nodeId); var node = document.getElementById(nodeId); var newNode = CreateNode(str, "span", css); // 追加一个新的结点 node.appendChild(newNode); node.style.display = "block"; } //刷新验证码 function reloadcode() { var linkList = window.parent.document.getElementsByTagName("link");//获取父窗口link标签对象列表 var head = document.getElementsByTagName("head").item(0); //外联样式 for (var i = 0; i < linkList.length; i++) { var l = document.createElement("link"); l.rel = 'stylesheet' l.type = 'text/css'; l.href = linkList[i].href; head.appendChild(l); } } function showAuthCode() { var authCodeDiv = document.getElementById('authCodeDiv'); authCodeDiv.setAttribute('style', 'display:'); } // 使用ajax登录 var xmlHttp; var domain; var url = '', unionid, isResetpwd, goldUName, level; var port; function getQueryStringRegExp(name) { var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i"); if (reg.test(location.href)) return unescape(RegExp.$2.replace(/\+/g, " ")); return ""; } /*验证用户信息*/ function validation(value, tip, tipKey, key) { if (value == "") { insertWithin(tipKey, tip); document.getElementById(key).focus(); return false; }else{ clearNode(tipKey); } return true; } /** * 获得验证成功后登录的跳转地址 */ function getPassUrl() { url = getQueryStringRegExp('url'); if (url == '') { port = top.location.port == "" ? "" : ":" + top.location.port; url = top.location.hostname + port + "/web/login-check.jsp"; } else if (url.indexOf("/") == 0) { port = top.location.port == "" ? "" : ":" + top.location.port; url = top.location.hostname + port + url; } } function test(){ $("#logining").hide(); $("#comeing").show(); } var ERROR_NUM = 3; var erroNum; /*登录*/ function login() { getPassUrl(); //登录号可以是用户名、邮箱、手机号 var loginId = document.getElementById("loginId").value.trim(); if (validation(loginId, "用户名不能为空", "tbr-login-tip", "loginId") != true) { return false; } level = checkPasswdRate(document.getElementById("passwd").value.trim()); var passwd = document.getElementById("passwd").value.trim(); var pwd = $.cookies.get("pwd"); if(passwd != pwd){ passwd = MD5(document.getElementById("passwd").value.trim().replace(/\%/g, "%25").replace(/\+/g, "%2B").replace(/\&/g, "%26")); } if (validation(passwd, "密码不能为空", "tbr-passwd-tip", "passwd") != true) { return false; } if(erroNum >=ERROR_NUM){ var authCode = $("#authCode").val(); if(validation(authCode, "验证码不能为空", "tbr-authCode-tip", "authCode") != true) { return false; } } $("#pwd").val(passwd); $("#passwd").val(passwd); if($("#auto").prop('checked') == true){ $.cookies.set("loginId",loginId,{hoursToLive: 100}); $.cookies.set("pwd",passwd,{hoursToLive: 100}); $.cookies.set("auto", "yes", {hoursToLive: 100}); }else{ $.cookies.set("loginId",""); $.cookies.set("pwd",""); $.cookies.set("auto", "no"); } //切换登录按钮文字 test(); caslogin(); } var webtrn_url = document.domain.indexOf('.demo.')>=0? 'http://sso.demo.webtrn.cn/auth' : 'https://sso.webtrn.cn/auth'; function caslogin() { document.getElementById("loginForm").action=webtrn_url; document.getElementById("errorPage").value="http://"+window.location.host+"/sso/ssoLogin_loginError.action?backURL=/index.jsp"; $("#loginForm").submit(); } //注册链接事件 function regedit() { var registerUrl = getQueryStringRegExp("registerUrl"); top.window.location.href = registerUrl+"?websiteId="+top.location.hostname; } //忘记密码链接事件 function forgetPasswork() { var forgetPasswordUrl = "/new/password/newGetPassword.action?logoUrl=/cms/res_base/webtrnthty/webtrn/images/logo.png"; //getQueryStringRegExp("forgetPasswordUrl"); top.window.location.href = forgetPasswordUrl; } function toResetPwd() { if (isResetpwd == true) { if (level != undefined && level < 1) { var r = confirm("您的密码过于简单,为了保障您的账户安全请重新设置密码"); if (r) { return getRootPath() + "/view/login/pwd/adminSetpwd.jsp?loginId=" + goldUName + "&loginType=3"; } } } return ""; } function reloadcode() { var url = isDemoSite() ? 'http://sso.demo.webtrn.cn' : 'https://sso.webtrn.cn'; var verify=document.getElementById('img_data'); verify.setAttribute('src', url + '/verifyCodeImg?' + Math.random()); jQuery("#showCode").show(); } function isDemoSite(){ return document.domain.indexOf('.demo.')!=-1; } function keydown(e) { var currKey = 0, e = e || event; currKey = e.keyCode || e.which || e.charCode;// 支持IE、FF if (currKey == 13) { login(); } } document.onkeydown = keydown; String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }