/** * Created by zhangchao8189888 on 16-4-27. */ var hdfLogin = function (rootElement, userSettings) { userSettings = userSettings || {}; var instance = new hdfLogin.Core(rootElement, userSettings); instance.init(); return instance; }; (function (window, hdfLogin) { var W = window, D = document, cnst = { AJAX_BASE_HOST : '://dev.passport.haodf.com/', AJAX_BASE_CONTROL : 'usernew/', LOGIN_OVER_TIME:0, DOCTOR_NO_WHITE_OVER_TIME:3, LOGIN_OVER_TODAY:5, // 原有服务usernew, 新增user系统 AJAX_USER_CONTROL: 'user' }, util = { isDef : function(o) { return typeof o != 'undefined'; }, isNum : function(o) { return typeof o == 'number' && o != null; }, isArray : function(o) { return o && (typeof(o) == 'object') && (o instanceof Array); }, isStr : function(o) { return o && (typeof o == 'string' || o.substring); }, stripDev : function(e){ var n=/(^|\.|\/)dev\./; return n.test(location.hostname)?e:e.replace(n,"$1"); }, text : function(url, fnCb, fnErr, _this) { url = this.stripDev(url) return $.ajax({ url : url, dataType : 'text', context : _this, success : function(data, textStatus, jqXHR) { fnCb && fnCb.call(this, data, textStatus, jqXHR); }, error : function(jqXHR, textStatus, errorThrown) { fnErr && fnErr.call(this, jqXHR, textStatus, errorThrown); } }); }, jsonp : function(config) { var httpHead = 'https:' == document.location.protocol ? 'https' : 'http'; var url = config.url; if (config.url) { config.url = httpHead + cnst.AJAX_BASE_HOST+cnst.AJAX_BASE_CONTROL + url; } config.url = this.stripDev(config.url); return $.ajax(config); }, // 极验请求ajax ajaxJsonp : function(config) { var httpHead = 'https:' == document.location.protocol ? 'https' : 'http'; var url = config.url; if (config.url) { config.url = httpHead + cnst.AJAX_BASE_HOST+url; } config.url = this.stripDev(config.url); return $.ajax(config); }, wait : function(fnCond, fnCb, nTime) { function waitFn() { if (fnCond()) { fnCb(); } else { W.setTimeout(waitFn, util.isNum(nTime) ? nTime : 100); } }; waitFn(); }, trim : function trim(str){ return str.replace(/[ ]/g,""); //去除字符算中的空格 }, isInt : function(val){ var digits = "1234567890"; for (var i = 0; i < val.length; i++) { if (digits.indexOf(val.charAt(i)) == -1) { return false; } } return true; } }; cnst.AJAX_BASE_HOST = util.stripDev(cnst.AJAX_BASE_HOST); var validate = { checkUserName : function () { var username = $.trim($("#js-login-alert").find('.username').val()); if (username == '') { $("#js-login-alert").find('.normal_username_err').html('登录名不能为空'); $("#js-login-alert").find('.normal_username_err').removeClass('login-dn'); } else { $("#js-login-alert").find('.normal_username_err').addClass('login-dn'); } }, checkPassWord : function () { var password = $.trim($("#js-login-alert").find('.password').val()); if (password != '') { $("#js-login-alert").find('.normal_password_err').addClass('login-dn'); return true; }else { $("#js-login-alert").find('.normal_password_err').removeClass('login-dn'); $("#js-login-alert").find('.normal_password_err').text('密码不能为空'); return false; } }, showCodeErrUI : function (status) { if ('default' == status) { $("#js-login-alert").find('.normal_code_err').hide(); $("#js-login-alert").find('.check_code').removeClass('input-shuiyin-pass'); } else if ('success' == status) { $("#js-login-alert").find('.normal_code_err').hide(); $("#js-login-alert").find('.check_code').addClass('input-shuiyin-pass'); } else if ('error' == status) { $("#js-login-alert").find('.normal_code_err').show(); $("#js-login-alert").find('.check_code').removeClass('input-shuiyin-pass'); } }, showNormalSendSMSErrUI : function (status,text) { if ('default' == status) { $("#js-login-alert").find('.normal_sms_err').hide(); $("#js-login-alert").find('.register_send_code').removeClass('input-shuiyin-pass'); } else if ('success' == status) { $("#js-login-alert").find('.normal_sms_err').hide(); $("#js-login-alert").find('.register_send_code').addClass('input-shuiyin-pass'); } else if ('error' == status) { if (text) { $("#js-login-alert").find('.normal_sms_err').text(text); } else { $("#js-login-alert").find('.normal_sms_err').text('短信验证码不能为空'); } $("#js-login-alert").find('.normal_sms_err').show(); $("#js-login-alert").find('.register_send_code').removeClass('input-shuiyin-pass'); } }, showMobileCheckCodeErrUI : function (status,text) { if ('default' == status) { $("#js-login-alert").find('.mobile_checkCode_err').hide(); $("#js-login-alert").find('.mobile_check_code').removeClass('input-shuiyin-pass'); } else if ('success' == status) { $("#js-login-alert").find('.mobile_checkCode_err').hide(); $("#js-login-alert").find('.mobile_check_code').addClass('input-shuiyin-pass'); } else if ('error' == status) { if (text) { $("#js-login-alert").find('.mobile_checkCode_err').text(text); } else { $("#js-login-alert").find('.mobile_checkCode_err').text('验证码不正确'); } $("#js-login-alert").find('.mobile_checkCode_err').show(); $("#js-login-alert").find('.mobile_check_code').removeClass('input-shuiyin-pass'); } }, showMobileSMSCodeErrUI : function (status,text) { if ('default' == status) { $("#js-login-alert").find('.mobile_code_err').hide(); $("#js-login-alert").find('.mobile_code').removeClass('input-shuiyin-pass'); } else if ('success' == status) { $("#js-login-alert").find('.mobile_code_err').hide(); $("#js-login-alert").find('.mobile_code').addClass('input-shuiyin-pass'); } else if ('error' == status) { if (text) { $("#js-login-alert").find('.mobile_code_err').text(text); } else { $("#js-login-alert").find('.mobile_code_err').text('验证码不正确'); } $("#js-login-alert").find('.mobile_code_err').show(); $("#js-login-alert").find('.mobile_code').removeClass('input-shuiyin-pass'); } }, showMobileUI : function (status,text) { if ('default' == status) { $("#js-login-alert").find('.mobile_number_err').addClass('login-dn'); $("#js-login-alert").find('.mobile_number').removeClass('input-shuiyin-pass'); } else if ('success' == status) { $("#js-login-alert").find('.mobile_number_err').addClass('login-dn'); $("#js-login-alert").find('.mobile_number').addClass('input-shuiyin-pass'); } else if ('error' == status) { if (text) { $("#js-login-alert").find('.mobile_number_err').text(text); } $("#js-login-alert").find('.mobile_number_err').removeClass('login-dn'); $("#js-login-alert").find('.mobile_number').removeClass('input-shuiyin-pass'); } }, doCheckMobile : function (str) { var pattern = /^(1[3][8][0][0][1][3][8][0][0][0-9])$/g; var pattern1 = /^1[3456789]([0-9])\1{8}$/g; if(null == str.match(/^[0-9\(\)\-\s]+$/g)) { return false; }else if(pattern.test(str) || pattern1.test(str)) { return false; } if(null == str.match(/^1[3456789][0-9]{9}$/)) { return false; } return true; }, isSimplePWD : function (pwd,username) { var flag1 = flag2 = 1; if(pwd.length < 6 || pwd.length>20) return 0; if(pwd == '121212' || pwd == '123456' || pwd == '1122' || pwd == '666888' || pwd == '888666' || pwd == username) return 1; var tmp = pwd.charAt(0); //判断是否是:1111111 for(i = 1; i < pwd.length; i++){ if(pwd.charAt(i) != tmp) { flag1 = 0; break; } } if(flag1 == 1) return 1; //判断是否是:1234567890 ,0987654321 var intercount = 0; for(i = 1; i < pwd.length; i++){ inter = tmp - pwd.charAt(i); if(inter != -1 && inter != 1 && inter != 9 && inter != -9){ break; } intercount += inter; tmp = pwd.charAt(i); } if(intercount == -1 * (pwd.length-1) || intercount == (pwd.length-1) )return 1; return 0; }, showMobilePasswordUI : function (status,text) { if ('default' == status) { $("#js-login-alert").find('.mobile_password_err').addClass('login-dn'); $("#js-login-alert").find('.register_password').removeClass('input-shuiyin-pass'); } else if ('success' == status) { $("#js-login-alert").find('.mobile_password_err').addClass('login-dn'); $("#js-login-alert").find('.register_password').addClass('input-shuiyin-pass'); } else if ('error' == status) { if (text) { $("#js-login-alert").find('.mobile_password_err').text(text); } $("#js-login-alert").find('.mobile_password_err').removeClass('login-dn'); $("#js-login-alert").find('.register_password').removeClass('input-shuiyin-pass'); } }, checkpwd : function (password) { if (password.length < 6 || password.length > 20){ return false; } return true; }, checkChinese : function (password) { if(/.*[\u4e00-\u9fa5]+.*$/.test(password)) { return false; } return true; } }; var checkWay = 'geetest'; hdfLogin.Core = function(rootElement, userSettings){ var instance = this; this.__loginTemplate = '
' + '用户登录注册
' + '请输入正确的手机号
' + '验证码不正确
' + '短信验证码不正确
' + '验证码不正确
' + '您注册的手机号为13000000000,请设置您的账号密码,以便下次登录时使用。
' + '提示语提示语
' + '您的登录名下有3个帐户,请选择登录:
' + '您可以点击上述用户名即可登录
' + '您注册的手机号为13000000000,请设置您的账号密码,以便下次登录时使用。
' + this.init = function () { instance.__loadCssFile(); if (false === instance.__checkJQuery()) { instance.__loadScriptFile(instance.__bindClickEvents); } else { instance.__bindClickEvents(); } instance.__failCnt = 0;//失败次数 instance.__errorCode = false;//失败次数 }; //this.__loginTemplate = null; this.__loadScriptFile = function (fn) { var domParent = (D.getElementsByTagName('head')[0] || D.body); var httpHead = 'https:' == document.location.protocol ? 'https' : 'http'; var o = D.createElement('script'),jqueryPath = httpHead+'://i1.hdfimg.com/ssi/usercenter/js/jquery.min.js'; o.type = 'text/javascript'; o.src = jqueryPath; o.setAttribute('scriptKey', jqueryPath); o.onload = o.onreadystatechange = function() { if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') { if(fn && typeof fn === "function") { fn(); } o.onload = o.onreadystatechange = null; } }; domParent.appendChild(o); }; this.__loadCssFile = function () { var domParent = (D.getElementsByTagName('head')[0] || D.body); var httpHead = 'https:' == document.location.protocol ? 'https' : 'http'; var o = D.createElement('link'),cssPath = httpHead+'://i1.hdfimg.com/ssi/usercenter/css/index_login_alert.css'; o.type = 'text/css'; o.href = cssPath; o.setAttribute('rel', 'stylesheet'); /*o.onload = o.onreadystatechange = function() { if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') { if(fn && typeof fn === "function") { fn(); } o.onload = o.onreadystatechange = null; } };*/ domParent.appendChild(o); }; this.__checkJQuery = function () { var bHasJquery = true; if (typeof window.jQuery == 'undefined') { bHasJquery = false; } return bHasJquery; }; this.showLoginDialog = function () { var url = '//dev.passport.haodf.com/usernew/showtemp'; if (instance.__loginTemplate != null) { instance.__show(instance.__loginTemplate); } else { util.text(url,function (data){ var html = data; instance.__loginTemplate = html; instance.__show(html); //console.log(jQuery.fn.jquery); },function (){ },this); } }; this.__show = function (html) { var loader=$("#js-login-mask"); if(loader.length==0){ $("body").append(html); } this.__rootElem = $("#js-login-alert"); instance.__alertPos($('#js-login-alert')); this.__bindBtnEvents(); this.__bindElemEvents(); $(window).resize(function(){ instance.__alertPos($('#js-login-alert')); }); $('#js-login-mask').show(); $('#js-login-alert').show(); }; this.__bindElemEvents = function () { instance.__rootElem.find('.username').focus(function(){ instance.__rootElem.find('.normal_username_err').addClass('login-dn'); }); instance.__rootElem.find('.username').blur(function(){ validate.checkUserName() }); instance.__rootElem.find('.username').keyup(function(e){ var username = instance.__rootElem.find('.username').val(); var keyCode = e.which; if (keyCode == 32) { instance.__rootElem.find('.username').val($.trim(username)); } }); instance.__rootElem.find('.password').focus(function(){ instance.__rootElem.find('.normal_password_err').addClass('login-dn'); }); instance.__rootElem.find('.password').blur(function(){ validate.checkPassWord() }); instance.__rootElem.find('.password').keyup(function(e){ var pwd = $.trim(instance.__rootElem.find('.password').val()); var keyCode = e.which; if (keyCode == 32) { instance.__rootElem.find('.password').val(util.trim(pwd)); } }); instance.__rootElem.find('.check_code').blur(function(){ var code = instance.__rootElem.find('.check_code').val(); var token = instance.__rootElem.find('#nor_register_token').val(); if ('' == code) { instance.__rootElem.find('.normal_code_err').show(); } else { instance.__checkCodeNormal(code,token); } }); instance.__rootElem.find('.check_code').keyup(function(){ var checkCode = $('.check_code').val(); if(checkCode.length == 4) { var code = instance.__rootElem.find('.check_code').val(); var token = instance.__rootElem.find('#nor_register_token').val(); instance.__checkCodeNormal(code,token); } }); instance.__rootElem.find('.register_captcha').click(function(){ instance.__changeRegisterVerifyCode(); validate.showCodeErrUI('default'); }); instance.__rootElem.find('.mobile_login_captcha').click(function(){ instance.__changeLoginVerifyCodeByMobile(); validate.showCodeErrUI('default'); }); /** * 手机验证绑定事件 */ instance.__rootElem.find('.mobile_number').focus(function(){ validate.showMobileUI('default'); }); instance.__rootElem.find('.mobile_number').blur(function(){ var mobileNumber = $.trim($(this).val()); if (mobileNumber == '') { validate.showMobileUI('error','手机号不能为空'); return false; } if (!util.isInt(mobileNumber)) { validate.showMobileUI('error','只能输入数字'); return false; } if (!validate.doCheckMobile(mobileNumber)) { validate.showMobileUI('error','请输入正确的手机号'); return false; } /*if (!instance.__getUserIdCntByUserName(mobileNumber, "QUICK")) { validate.showMobileUI('error'); instance.__rootElem.find('.mobile_number_err').text('该手机号未注册,请注册'); instance.__rootElem.find(".set_login_password").removeClass("login-dn"); instance.__rootElem.find(".agreement-p").removeClass("login-dn"); instance.__registerMobileNumber = mobileNumber; return false; } else { instance.__rootElem.find(".set_login_password").addClass("login-dn"); instance.__rootElem.find(".agreement-p").addClass("login-dn"); validate.showMobileUI('success'); }*/ instance.__getUserIdCntByUserName(mobileNumber,"QUICK",function () { instance.__rootElem.find(".set_login_password").addClass("login-dn"); instance.__rootElem.find(".agreement-p").addClass("login-dn"); validate.showMobileUI('success'); },function () { // 产品同意,原有弹窗不允许注册,此次改动提供注册功能,未注册手机号不提示红字 // validate.showMobileUI('error'); // instance.__rootElem.find('.mobile_number_err').text('该手机号未注册,请注册'); instance.__rootElem.find(".set_login_password").removeClass("login-dn"); instance.__rootElem.find(".agreement-p").removeClass("login-dn"); //instance.__rootElem.find(".register_mobile_number").text(mobileNumber); instance.__registerMobileNumber = mobileNumber; }) }); instance.__rootElem.find('.mobile_number').keyup(function (e) { var mobileNumber = instance.__rootElem.find('.mobile_number').val(); var keyCode = e.which; if (keyCode == 32) { instance.__rootElem.find('.mobile_number').val(util.trim(mobileNumber)); } }); instance.__rootElem.find('.mobile_code').keyup(function(){ var mobileNumber = $.trim(instance.__rootElem.find('.mobile_number').val()); var mobileCode = $.trim(instance.__rootElem.find('.mobile_code').val()); if (mobileCode.length == 6) { if (instance.__oldCheckCode != mobileCode) { instance.__oldCheckCode = mobileCode; } else { return false; } instance.__checkMobileCode(mobileNumber, mobileCode); } }); instance.__rootElem.find('.mobile_code').blur(function(){ var mobileNumber = $.trim(instance.__rootElem.find('.mobile_number').val()); var mobileCode = $.trim(instance.__rootElem.find('.mobile_code').val()); if ('' == mobileCode) { validate.showMobileSMSCodeErrUI('error','短信验证码不能为空'); return false; } if (mobileCode.length != 0) { instance.__checkMobileCode(mobileNumber, mobileCode); } }); //针对手机登录的时候的水印验证码的触发方法实现 instance.__rootElem.find('.mobile_check_code').blur(function(){ var code = instance.__rootElem.find('.mobile_check_code').val(); var checkCode = $('.mobile_check_code').val(); if ('' == code) { validate.showMobileCheckCodeErrUI('error','请输入验证码'); }else if (checkCode.length != 4) { validate.showMobileCheckCodeErrUI('error','验证码错误'); }else { instance.__verifyCode(); } }); //针对手机登录的时候的水印验证码的触发方法 instance.__rootElem.find('.mobile_check_code').keyup(function(){ var checkCode = $('.mobile_check_code').val(); if(checkCode.length == 4) { instance.__verifyCode(); } }); /***注册时设置密码对密码进行校验***/ instance.__rootElem.find('.register_password').focus(function(){ validate.showMobilePasswordUI('default'); }); instance.__rootElem.find('.register_password').blur(function(){ var pwd = $.trim(instance.__rootElem.find('.register_password').val()); var mobileNumber = $.trim(instance.__rootElem.find('.mobile_number').val()); if (!instance.__checkPassword(mobileNumber, pwd)) { return false; } if(pwd.length == 0) { validate.showMobilePasswordUI('error','密码必须是6-20位字母、数字或字符'); } }); instance.__rootElem.find('.register_password').keyup(function(e){ var pwd = $.trim(instance.__rootElem.find('.register_password').val()); var mobileNumber = $.trim(instance.__rootElem.find('.mobile_number').val()); var keyCode = e.which; if (keyCode == 32) { instance.__rootElem.find('.register_password').val(util.trim(pwd)); } if (pwd.length != 0 ) { instance.__checkPassword(mobileNumber, pwd); } else { validate.showMobilePasswordUI('default'); } }); }; this.__checkCodeNormal = function (checkCode,registerToken) { util.jsonp({ type:"get", url:'ajaxcheckverifycode?verifyStr='+encodeURIComponent(checkCode)+'&token='+encodeURIComponent(registerToken), dataType:'jsonp', jsonp:'callback', success:function(res) { var data = res.ret; if (1 == data) { validate.showCodeErrUI('error'); instance.__changeRegisterVerifyCode(); instance.__errorCode = true; } else { validate.showCodeErrUI('success'); instance.__errorCode = false; } } }); }; this.__changeRegisterVerifyCode = function () { util.jsonp({ type:"get", url:'ajaxchangeverifycode', dataType:'jsonp', jsonp:'callback', success:function(res) { var data = res.data; var newToken=data['token']; var newCid=data['captchaId']; //validate.showCodeErrUI('default'); var httpHead = 'https:' == document.location.protocol ? 'https' : 'http'; instance.__rootElem.find(".register_captcha").attr('src', httpHead+util.stripDev(cnst.AJAX_BASE_HOST)+"captcha.php?type=login&width=100&height=38&size=20&token="+newToken); $("#nor_register_token").val(newToken); $("#nor_register_captchaId").val(newCid); instance.__rootElem.find(".check_code").val(''); } }); } this.__bindBtnEvents = function () { instance.__tabnav($('#js-tab-nav'),$('#js-tab-content')); instance.__agreeCheck($('#js-agr-check'),'agreement-none'); instance.__interValObj; instance.__loginCurCount = 60; // instance.__loginCurCount = 5; instance.__rootElem.find(".mobile_code_btn").click(function(){ if(checkWay == 'haodf'){ instance.__rootElem.find('.mobile_code').val(''); instance.__sendMessage();return false; }else { var mobileNumber = $.trim(instance.__rootElem.find('.mobile_number').val()); //前端检验手机号格式 if (!validate.doCheckMobile(mobileNumber)) { validate.showMobileUI('error'); return false; }else { //注册和登录传递不同的source var source = 'Login'; instance.__getUserIdCntByUserName(mobileNumber,"QUICK",function () { instance.__initJiyan(source); },function () { source = 'Register'; instance.__initJiyan(source); }); } } }); $("#item-timer-usually").click(function(){ instance.__rootElem.find('.register_send_code').val(''); instance.__sendMessage();return false; }); $("#js-close-mask").click(function(){ instance.__closemask(); }); instance.__rootElem.find(".submit_normal").click(function(){ instance.__loginByNormal();return false; }); instance.__rootElem.find(".submit_mobile").click(function(){ instance.__loginByMobile();return false; }); $('#js-choose-user>li').click(function(){ $(this).addClass('cur').siblings().removeClass('cur'); }); }; this.__loginByNormal = function () { var username = $.trim(instance.__rootElem.find(".username").val()); var password = $.trim(instance.__rootElem.find('.password').val()); var checkMobileCode = $.trim(instance.__rootElem.find('.checkMobileCode').val()); var checkCode = $.trim(instance.__rootElem.find('.check_code').val()); var mobileCodeForNormal = $('#pswNormal').val(); if (!instance.__rootElem.find('.check_code_div').hasClass('login-dn')) { if ('' == checkCode) { instance.__rootElem.find('.normal_code_err').show(); return false; } else if (instance.__errorCode) { return false; } if (!instance.__rootElem.find('.normal_code_err').hasClass('login-dn')) { validate.showCodeErrUI('error'); return false; } } if (!instance.__rootElem.find('.checkMobileCode').hasClass('login-dn')) { } if (false == instance.__isShowErrorTip(username, 'normal_username_err', '请输入正确的登录名')) { return false; } if (false == validate.checkPassWord()) { return false; } if( false == instance.__isShowErrorTip(password, 'normal_password_err', '密码不正确')) { validate.showCodeErrUI('default'); return false; } if (instance.__sendRegisterSMS) { var registerSendSMS = instance.__rootElem.find('.register_send_code').val(); if ('' == registerSendSMS) { validate.showNormalSendSMSErrUI('error'); return false; } } /*if (false == instance.__getUserIdCntByUserName(username,"NORMAL")) { //instance.__rootElem.find('.normal_username_err').html('用户名不存在'); instance.__rootElem.find('.normal_username_err').html('登录名或密码错误'); instance.__rootElem.find('.normal_username_err').removeClass('login-dn'); return false; } else { if (instance.__sendRegisterSMS) { var registerSendSMS = instance.__rootElem.find('.register_send_code').val(); instance.__addWhiteUserLogin(username,password,registerSendSMS); } else if (validate.doCheckMobile(username)) { instance.__ajaxGetUsersByUsername(username,password, checkCode); } else { instance.__loginNormal(); } }*/ // 正常登陆逻辑 function doLogin() { instance.__getUserIdCntByUserName(username,"NORMAL",function () { if (instance.__sendRegisterSMS) { var registerSendSMS = instance.__rootElem.find('.register_send_code').val(); instance.__addWhiteUserLogin(username,password,registerSendSMS); } if (validate.doCheckMobile(username)) { instance.__ajaxGetUsersByUsername(username,password, checkCode); } else { if (instance.__failCnt >= cnst.LOGIN_OVER_TIME && checkWay == 'geetest'){ instance.__initUsernameJiyan() }else { // loginNoraml修改为二次校验方法verifyWay正常登录传递空 instance.__loginNormal(0,this,{verifyWay: ''}); } } },function () { instance.__rootElem.find('.normal_username_err').html('登录名或密码错误'); instance.__rootElem.find('.normal_username_err').removeClass('login-dn'); }) } var usernameReg = /[^0-9a-zA-Z]/g; if(usernameReg.test(username)) { instance.__checkChineseUserNameLogin(username, password, doLogin); return false; } doLogin(); }; this.__ajaxGetUsersByUsername = function (username,password, checkCode) { var token = $("#nor_register_token").val(); util.jsonp({ type:"get", url:'ajaxGetUsersByUsername?username='+encodeURIComponent(username)+'&token='+encodeURIComponent(token)+'&password='+encodeURIComponent(password)+'&checkCode='+encodeURIComponent(checkCode) + '&verifyWay=' + checkWay, dataType:'jsonp', jsonp:'callback', success:function(data) { var ret = data.ret; var code = data.errorCode; var resData = data.data; if(0 == ret) { if (100010 == code) { var userDatas = data.data; var users = userDatas.users; var password = userDatas.password; // 多用户登录,错误三次出极验 if (checkWay == 'geetest' && instance.__failCnt >= cnst.LOGIN_OVER_TIME){ instance.__getVerifiableWay(username, function(result){ var sdkInfo = { geetest_challenge: result.geetest_challenge, geetest_validate: result.geetest_validate, geetest_seccode: result.geetest_seccode } var params = { sdkInfo:sdkInfo, uniqueId: username, clientType: 'pc', actions: 'Login', sourceType: 'Login', } if (userDatas.cnt > 1) { $("#js-choose-user").html(''); instance.__rootElem.find(".select_user").show(); instance.__rootElem.find(".normal_login").hide(); //sinstance.__rootElem.find(".single-more-user").addClass('login-dn'); instance.__rootElem.find(".select_user_text").text('您的登录名下有'+userDatas.cnt+'个帐户,请选择登录:'); } for(var i =0; i < users.length; i++) { $("#js-choose-user").append('验证码错误
'); } else if (10004 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('今日验证码次数已达上限,请明天再试'); } else if (10005 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('亲,操作太频繁了或者已经超过上限
'); } else if (10006 == code) { instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } else if (10007 == code) { validate.showMobileCheckCodeErrUI('error'); instance.__changeLoginVerifyCodeByMobile(); }else if (10008 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('发送验证码太多今天不再发送
'); }else if (100012 == code) { // validate.showMobileUI('error',"该手机号未注册,请注册"); // instance.__rootElem.find(".set_login_password").removeClass("login-dn"); instance.__rootElem.find(".agreement-p").removeClass("login-dn"); instance.__registerMobileNumber = mobileNumber; }else{ validate.showMobileSMSCodeErrUI('success'); } } }, error : function () { validate.showMobileUI('error',"抱歉,系统出问题了"); } }); }; this.__doubleLogin = function () { var userId = $(this).attr("data-id"); var mobileCode = $(this).attr("data-code"); util.jsonp({ type:"get", url:'doublelogin?uid='+encodeURIComponent(userId)+'&mobileCode='+encodeURIComponent(mobileCode), dataType:'jsonp', jsonp:'callback', success:function(data) { if( 0 == data.ret) { instance.__loginSuccess(); } else { if(10086 == data.errorCode){ // 黑名单用户,跳转到指定页面 window.location.href = data.data; return; } validate.showMobileUI('error','登录失败'); } }, error : function () { validate.showMobileUI('error',"抱歉,系统出问题了"); } }); }; this.__loginSuccess = function () { this.__isSuccessLogin = true; //alert("登录成功"); if (instance.__clickObjHref) { location.href = instance.__clickObjHref; } else { window.location.reload(); } }; /*页面居中展示*/ this.__alertPos = function(obj) { var widthL = ($(window).width()-obj.width())/2; var heightT = ($(window).height()-obj.height())/2; obj.css({ left: widthL+'px', margin: 0 }); obj.css({ top: heightT+'px', margin: 0 }); }; /*登录框切换交互*/ this.__tabnav = function (nav,list){ nav.children().click(function(){ var clinum = $(this).parent().children().index($(this)); list.children().eq(clinum).show().siblings().hide(); $(this).addClass('cur').siblings().removeClass('cur'); }) }; /*同意协议交互*/ this.__agreeCheck = function (btn,none){ btn.click(function(){ if($(this).hasClass(none)){ $(this).removeClass(none); } else { $(this).addClass(none); } }); }; /*关闭按钮调用方法*/ this.__closemask = function (){ $('#js-login-mask').remove(); $('#js-login-alert').remove(); // 解决验证码倒计时停止bug,关闭弹窗清空定时器 instance.__loginCurCount = 0; window.clearInterval(instance.__interValObj); instance.__sendRegisterSMS = false; }; this.__showTime = function (obj){ // 清除定时器 instance.__loginCurCount = 0; window.clearInterval(instance.__interValObj); if(instance.__loginCurCount==0){ instance.__loginCurCount = 60; // instance.__loginCurCount = 5; } obj.attr("disabled", "true"); obj.val("剩余"+instance.__loginCurCount + "秒"); obj.addClass("pass-item-disable"); instance.__interValObj = window.setInterval(SetRemainTime, 1000); function SetRemainTime() { if (instance.__loginCurCount == 0) { window.clearInterval(instance.__interValObj); obj.removeAttr("disabled"); obj.removeClass("pass-item-disable"); obj.val("获取验证码"); } else { instance.__loginCurCount--; obj.val("剩余"+instance.__loginCurCount + "秒"); } } }; this.__sendWhiteUserMessage = function (e,params) { // if (true == instance.__sendMessageFlag) { // return false; // } // instance.__sendMessageFlag = true; var param = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var mobileNumber = $.trim(instance.__rootElem.find('.nor_whiteUser_mobile').val()); var token = $.trim($('#nor_register_token').val()); var verify = $.trim(instance.__rootElem.find('.check_code').val()); var optType = 'Login'; //前端检验手机号格式 if (!validate.doCheckMobile(mobileNumber)) { validate.showMobileUI('error'); return false; } instance.__rootElem.find(".normal_code_btn").attr("disabled", "true"); util.jsonp({ url:'ajaxsendmobilecode4login?mobileNumber='+encodeURIComponent(mobileNumber)+'&sourceType='+encodeURIComponent(optType)+'&token='+encodeURIComponent(token)+'&verify='+encodeURIComponent(verify), dataType:'jsonp', data: param, jsonp:'callback', success:function(res) { instance.__rootElem.find(".normal_code_btn").removeAttr("disabled"); var ret = res.ret; var code = res.errorCode; if(0 == ret) { instance.__showTime(instance.__rootElem.find(".normal_code_btn")); validate.showNormalSendSMSErrUI('error'); instance.__rootElem.find('.normal_sms_err').html('验证码发送成功
'); return false; } else { if (10002 == code) { validate.showNormalSendSMSErrUI('error'); instance.__rootElem.find('.normal_sms_err').text('操作过于频繁,请稍后尝试'); } else if (10004 == code) { validate.showNormalSendSMSErrUI('error'); instance.__rootElem.find('.normal_sms_err').text('操作过于频繁,请稍后尝试'); } else if (10003 == code) { validate.showNormalSendSMSErrUI('error'); instance.__rootElem.find('.normal_sms_err').text('今日验证码次数已达上限,请明天再试'); } else if (10005 == code) { if (checkWay == 'haodf'){ instance.__rootElem.find('.check_code_div').show(); validate.showNormalSendSMSErrUI('default'); instance.__changeRegisterVerifyCode(); } } else if (10006 == code) { validate.showNormalSendSMSErrUI('error'); instance.__changeRegisterVerifyCode(); }else if (10004 == code) { validate.showNormalSendSMSErrUI('error'); instance.__rootElem.find('.normal_code_err').html('亲,操作太频繁了或者已经超过上限
'); }else if (10008 == code) { validate.showNormalSendSMSErrUI('error'); instance.__rootElem.find('.normal_code_err').html('亲,操作太频繁了或者已经超过上限
'); }else if (10010 == code){ validate.showNormalSendSMSErrUI('error'); instance.__rootElem.find('.normal_code_err').html('校验失败,请重试
'); } else{ validate.showCodeErrUI('success'); } } return false; }, error: function(e){ } }); }; this.__sendMessage = function () { var mobileNumber = $.trim(instance.__rootElem.find('.mobile_number').val()); var token = $.trim($('#mobile_register_token').val()); var verify = $.trim(instance.__rootElem.find('.mobile_check_code').val()); var optType = 'Login'; //前端检验手机号格式 if (!validate.doCheckMobile(mobileNumber)) { validate.showMobileUI('error'); return false; } /* if (!instance.__getUserIdCntByUserName(mobileNumber, "QUICK")) { *//*validate.showMobileUI('error'); instance.__rootElem.find('.mobile_number_err').text('该手机号未注册,请注册'); instance.__rootElem.find(".set_login_password").removeClass("login-dn"); instance.__registerMobileNumber = mobileNumber; return false;*//* optType = 'Register'; } else { instance.__rootElem.find(".set_login_password").addClass("login-dn"); validate.showMobileUI('success'); }*/ instance.__getUserIdCntByUserName(mobileNumber,"QUICK",function () { instance.__rootElem.find(".set_login_password").addClass("login-dn"); validate.showMobileUI('success'); instance.__ajaxSendMessage(mobileNumber,optType,token,verify); // if (checkWay == 'haodf') { // instance.__rootElem.find(".set_login_password").addClass("login-dn"); // validate.showMobileUI('success'); // instance.__ajaxSendMessage(mobileNumber,optType,token,verify); // }else { // instance.__initJiyan(mobileNumber,optType); // } },function () { optType = 'Register'; instance.__ajaxSendMessage(mobileNumber,optType,token,verify); }); }; this.__ajaxSendMessage = function (mobileNumber,optType,token,verify) { if (true == instance.__sendMessageFlag) { return false; } instance.__rootElem.find(".mobile_code_btn").attr("disabled", "true"); instance.__sendMessageFlag = true; util.jsonp({ type:"get", url:'ajaxsendmobilecode4login?mobileNumber='+encodeURIComponent(mobileNumber)+'&sourceType='+encodeURIComponent(optType)+'&token='+encodeURIComponent(token)+'&verify='+encodeURIComponent(verify), dataType:'jsonp', jsonp:'callback', complete: function () { instance.__sendMessageFlag = false; }, success:function(res) { instance.__rootElem.find(".mobile_code_btn").removeAttr("disabled"); var ret = res.ret; var code = res.errorCode; if(0 == ret) { instance.__showTime(instance.__rootElem.find(".mobile_code_btn")); validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('验证码发送成功
'); return false; } else { if (10001 == code) { validate.showMobileUI('error'); instance.__rootElem.find('.mobile_number_err').text('请输入正确的手机号'); }else if (10002 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('操作过于频繁,请稍后尝试
'); } else if (10004 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('操作过于频繁,请稍后尝试
'); } else if (10003 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('今日验证码次数已达上限,请明天再试'); } else if (10005 == code) { instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } else if (10006 == code) { validate.showMobileCheckCodeErrUI('error'); instance.__changeLoginVerifyCodeByMobile(); }else if (10004 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('亲,操作太频繁了或者已经超过上限
'); }else if (10008 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('亲,操作太频繁了或者已经超过上限
'); }else{ validate.showMobileSMSCodeErrUI('success'); } } return false; } }); }; this.__initJiyan = function (sourceType){ var source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'Login'; if(true === instance._initFlag) { return; } instance._initFlag = true; var mobileNumber = $.trim(instance.__rootElem.find('.mobile_number').val()); var optType = 'QUICK'; util.ajaxJsonp({ url:"user/getVerifiableWayJsonFormat", data:{ clientType:"pc", actions:"Login", initTryTime:true, uniqueId:mobileNumber, sourceType:optType }, jsonp:'callback', type:"get", dataType:'jsonp', async:false, success: function(res) { if(res.errorCode == '0') { var data = res.data; var way = data.way; checkWay = way; if(way == 'geetest') { initGeetest({ // 以下配置参数来自服务端 SDK gt: data.verifyInfo.gt, challenge: data.verifyInfo.challenge, offline: data.verifyInfo.offline, neweeaptcha: data.verifyInfo.new_captcha, product:'bind', uniqueId:mobileNumber }, function (captchaObj) { captchaObj.onReady(function() { instance._initFlag = false; captchaObj.verify(); }) .onError(function(){ instance._initFlag= false; }) .onSuccess(function(){ var result = captchaObj.getValidate(); util.ajaxJsonp({ url: 'user/ajaxSendMobileCode4LoginJY', dataType:'jsonp', data: { clientType:'pc', actions:'Login', uniqueId:mobileNumber, sourceType:source, sdkInfo: { geetest_challenge: result.geetest_challenge, geetest_validate: result.geetest_validate, geetest_seccode: result.geetest_seccode } }, success: function(res) { var code = res.errorCode; if(0 == code) { instance.__showTime(instance.__rootElem.find(".mobile_code_btn")); validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('验证码发送成功
'); } else { instance._mobileError(code); } }, error: function(e) { instance._initFlag = false; checkWay = 'haodf'; instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } }) }) }) } else { instance._initFlag = false; checkWay = 'haodf'; instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } } else { var code = res.errorCode; instance._mobileErroe(code); } }, error: function(e) { instance._initFlag= false; checkWay = 'haodf'; instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } }) }; this.__initSMSJiyan = function (){ if(true === instance._initSMSFlag) { return; } if(checkWay == 'haodf'){ instance.__sendWhiteUserMessage(); return; } instance._initSMSFlag = true; // 解决验证码倒计时停止bug,关闭弹窗清空定时器 instance.__loginCurCount = 0; window.clearInterval(instance.__interValObj); var username = $.trim(instance.__rootElem.find(".username").val()); var password = $.trim(instance.__rootElem.find('.password').val()); var optType = 'NORMAL'; util.ajaxJsonp({ url:"user/getVerifiableWayJsonFormat", data:{ clientType:"pc", actions:"Login", initTryTime:true, uniqueId:username, sourceType:optType }, jsonp:'callback', type:"get", dataType:'jsonp', async:false, success: function(res) { if(res.errorCode == '0') { var data = res.data; var way = data.way; checkWay = way; if(way == 'geetest') { initGeetest({ // 以下配置参数来自服务端 SDK gt: data.verifyInfo.gt, challenge: data.verifyInfo.challenge, offline: data.verifyInfo.offline, neweeaptcha: data.verifyInfo.new_captcha, product:'bind', uniqueId:username }, function (captchaObj) { captchaObj.onReady(function() { instance._initSMSFlag = false; captchaObj.verify(); }) .onError(function(){ instance._initSMSFlag= false; }) .onSuccess(function(){ var result = captchaObj.getValidate(); var params = { clientType:'pc', actions:'Login', uniqueId:username, sourceType:'Login', verifyWay:checkWay, sdkInfo: { geetest_challenge: result.geetest_challenge, geetest_validate: result.geetest_validate, geetest_seccode: result.geetest_seccode } } instance.__sendWhiteUserMessage(1,params); }) }) } else { instance._initSMSFlag = false; checkWay = 'haodf'; instance.__rootElem.find('.check_code_div').show(); validate.showNormalSendSMSErrUI('default'); instance.__changeRegisterVerifyCode(); } } else { var code = res.errorCode; instance._mobileErroe(code); } }, error: function(e) { instance._initSMSFlag = false; checkWay = 'haodf'; instance.__rootElem.find('.check_code_div').show(); validate.showNormalSendSMSErrUI('default'); instance.__changeRegisterVerifyCode(); } }) }; this.__initUsernameJiyan = function (isSecondValid){ // 是否需要进行二次校验,密码错误等情况不需要 var isSecond = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; if(true === instance._initFlag) { return; } instance._initFlag = true; var username = $.trim(instance.__rootElem.find(".username").val()); var password = $.trim(instance.__rootElem.find('.password').val()); var optType = 'NORMAL'; util.ajaxJsonp({ url:"user/getVerifiableWayJsonFormat", data:{ clientType:"pc", actions:"Login", initTryTime:true, uniqueId:username, sourceType:optType }, jsonp:'callback', type:"get", dataType:'jsonp', async:false, success: function(res) { instance._initFlag = false; if(res.errorCode == '0') { var data = res.data; var way = data.way; checkWay = way; if(way == 'geetest') { initGeetest({ // 以下配置参数来自服务端 SDK gt: data.verifyInfo.gt, challenge: data.verifyInfo.challenge, offline: data.verifyInfo.offline, neweeaptcha: data.verifyInfo.new_captcha, product:'bind', uniqueId:username }, function (captchaObj) { captchaObj.onReady(function() { instance._initFlag = false; captchaObj.verify(); }) .onError(function(){ instance._initFlag= false; }) .onSuccess(function(){ if(!isSecond) { return; } var result = captchaObj.getValidate(); var sdkInfo = { geetest_challenge: result.geetest_challenge, geetest_validate: result.geetest_validate, geetest_seccode: result.geetest_seccode } var params = { sdkInfo:sdkInfo, uniqueId: username, clientType: 'pc', actions: 'Login', sourceType: 'Login', } instance.__loginNormal(0,this,params); }) }) } else { instance._initFlag = false; checkWay = 'haodf'; instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } } else { var code = res.errorCode; instance._mobileErroe(code); } }, error: function(e) { instance._initFlag= false; checkWay = 'haodf'; instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } }) }; this._mobileError = function(code){ // 手机号错误 if (40001 == code) { validate.showMobileUI('error'); instance.__rootElem.find('.mobile_number_err').text('请输入正确的手机号'); }else if (40002 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('操作过于频繁,请稍后尝试
'); } else if (40003 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('今日验证码次数已达上限,请明天再试'); } else if (40004 == code) { validate.showMobileSMSCodeErrUI('error'); instance.__rootElem.find('.mobile_code_err').html('亲,操作太频繁了或者已经超过上限
'); }else if (2002 == code || 2003 == code) { // 极验二次校验失败,走水印 checkWay = 'haodf'; instance.__rootElem.find('.mobile_check_code_div').show(); validate.showMobileCheckCodeErrUI('default'); instance.__changeLoginVerifyCodeByMobile(); } else{ validate.showMobileSMSCodeErrUI('success'); } } this.__changeLoginVerifyCodeByMobile = function () { util.jsonp({ type:"get", url:'ajaxchangeverifycode', dataType:'jsonp', jsonp:'callback', success:function(res) { var data = res.data; var newToken=data['token']; var newCid=data['captchaId']; //validate.showMobileCheckCodeErrUI('default'); var httpHead = 'https:' == document.location.protocol ? 'https' : 'http'; instance.__rootElem.find(".mobile_login_captcha").attr('src', httpHead+util.stripDev(cnst.AJAX_BASE_HOST)+"captcha.php?type=login&width=100&height=38&size=20&token="+newToken); $("#mobile_register_token").val(newToken); $("#mobile_register_captchaId").val(newCid); instance.__rootElem.find(".mobile_check_code").val(''); } }); }; this.__isAjaxLogin = function (){ if (1 == instance.__ajaxDone) { return false; } else if (2 == instance.__ajaxDone) { return true; }else { instance.__ajaxDone = 1; util.jsonp({ type:"get", url:'checkIsLogin', dataType:'jsonp', jsonp:'callback', success:function(res) { if (0 == res.ret) { instance.__fIsLogin =true; } else { instance.__fIsLogin =false; } instance.__ajaxDone = 2; } }); } }; this.__bindClickEvents =function () { if (!util.isArray(rootElement)) { rootElement = [rootElement]; } for (var i = 0; i < rootElement.length; i++) { $(rootElement[i]).click(function (event, arg1){ if (arg1) { return true; } var bool = false; instance.__ajaxDone = 0; var obj = $(this); util.wait(instance.__isAjaxLogin,function (){ bool = instance.__fIsLogin; if (instance.__fIsLogin) { location.href = obj.attr("href"); } else { instance.__clickObjHref = obj.attr("href"); instance.showLoginDialog(); } }); return false; }); } }; this.__isShowErrorTip = function (str, className, strTip) { if (str == '') { instance.__rootElem.find('.'+className).html(strTip); instance.__rootElem.find('.'+className).removeClass('login-dn'); return false; } else if (str.length > 50) { instance.__rootElem.find('.'+className).html(strTip); instance.__rootElem.find('.'+className).removeClass('login-dn'); } else { instance.__rootElem.find('.'+className).html(''); instance.__rootElem.find('.'+className).addClass('login-dn'); return true; } }; } })(window, hdfLogin);