function byWay(type) { $('#recoveryWay').val(type); $("#one").hide(); $("#two").show(); changeSh('two'); $("#grxx").attr("class", "current_prev"); $("#zjxx").attr("class", "current"); $('#recoveryWay').val(type) } function changeSh(step) { var type = $('#recoveryWay').val() var $currentstep = $('#' + step + '') var $hideEle = $currentstep.find('.form-' + step + '') $hideEle.hide(); if (type == '1') { $currentstep.find('.form-' + step + '-phone').show() } else if (type == '2') { $currentstep.find('.form-' + step + '-email').show() } else if (type == '3') { $currentstep.find('.form-' + step + '-question').show() } if (step == 'three' && type == '2') { $currentstep.find('.three-btns').hide() } if (step == 'two') { if (type == '1') { captcha($(".form-two-phone")) } if (type == '2') { captcha($(".form-two-email")) } if (type == '3') { captcha($(".form-two-question")) } } } function captcha(obj) { var captcha = obj.find(".captcha-img"); captcha.attr("src","captcha.html?ts=" + new Date().getMilliseconds()); captcha.bind("click",function(){ captcha.attr("src","captcha.html?ts="+new Date().getMilliseconds()); }); } function reone() { $("#one").show(); $("#two").hide(); $("#grxx").attr("class", "current"); $("#zjxx").attr("class", ""); } function two() { var type = $('#recoveryWay').val(); if (type == 1) { getPwdByMobile() } if (type == 2) { getPwdByMail() } if (type == 3) { getPwdByQuestion() } } function three() { var type = $('#recoveryWay').val(); if (type == 1) { validCode() } if (type == 3) { validAnswer() } } function four() { var type = $('#recoveryWay').val(); if (type == 1) { var uid = $("#uid").val(); var mobile = $("#mobile").val(); var code = $("#code").val(); resetPassword(uid,mobile,code,null,null,"mobile") } if (type == 3) { var uid = $("#uid").val(); var answer = $("#answer").val(); var showBirthDay = $("#showBirthDay").val(); var birthday = ""; if (showBirthDay) { birthday = $("#birthday").val(); } resetPassword(uid,null,null,birthday,answer,"question") } } function retwo() { $("#three").hide(); $("#two").show(); $("#grxx").attr("class", "current_prev"); $("#zjxx").attr("class", "current"); $("#qzxx").attr("class", ""); } function rethree() { $("#four").hide(); $("#three").show(); $("#grxx").attr("class", "done"); $("#zjxx").attr("class", "current_prev"); $("#qzxx").attr("class", "current"); $("#qzfs").attr("class", "last"); } function getPwdByMobile() { var $username = $("#userId"); var $mobile = $("#mobile"); var $captcha = $("#captcha"); if (!checkRequired($username) || !checkRequired($mobile) || !checkRequired($captcha)) { return; } var phone_number = $.trim($mobile.val()); if (phone_number.length != 11 || !phone_number.match(/^1[1-9][0-9]\d{4,8}$/)) { showError($mobile,mobilephone) return; } $.ajax({ type: "POST", url: "getBackPassword.do", dataType: "json", data: { userId: $.trim($username.val()), mobile: $mobile.val(), captcha: $captcha.val(), type: "mobile", step: 1 }, success: function (data) { if (data.success) { $("#sign").val(data.data.sign) $("#question").text(data.data.question) $("#uid").val(data.data.uid); sendCode($(".send-verifation")); $("#two").hide(); $("#three").show(); changeSh('three') $("#grxx").attr("class", "done"); $("#zjxx").attr("class", "current_prev"); $("#qzxx").attr("class", "current"); } else { captcha($(".form-two-phone")); var code = data.code var message = data.message if (code == 1) {//用户名错误 showError($username,message); return; } if (code == 2) {//手机号错误 showError($mobile,message); return; } if (code == 3) {//验证码错误 showError($captcha,message); return; } showError($username,message) } } }); } function getPwdByMail() { var $userId = $("#mail_userId"); var $mail = $("#mail"); var $captcha = $("#mail_captcha"); if (!checkRequired($userId) || !checkRequired($mail) || !checkRequired($captcha)) { return; } if (!/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test($.trim($mail.val()))) { showError($mail,email); return; } $.ajax({ type: "POST", url: "getBackPassword.do", dataType: "json", data: { userId: $.trim($userId.val()), mail: $.trim($mail.val()), captcha: $captcha.val(), service: $("#service").val(), type: "mail", step: 1 }, success: function (data) { if (data.success) { $("#sign").val(data.data.sign); $("#uid").val(data.data.uid); $(".three-p").text(data.data.msgTip).show(); $("#passwordPolicy").text(data.data.passwordPolicy); $("#two").hide(); $("#three").show(); changeSh('three'); $("#grxx").attr("class", "done"); $("#zjxx").attr("class", "current_prev"); $("#qzxx").attr("class", "current"); } else { captcha($(".form-two-email")); var code = data.code; var message = data.message; if (code == 1) {//用户名错误 showError($userId,message); return; } if (code == 4) { showError($mail,message); } if (code == 8) {//邮箱错误 showError($mail,message); return; } if (code == 3) {//验证码错误 showError($captcha,message); return; } showError($userId,message) } } }); } function getPwdByQuestion() { var $userId = $("#question_userId"); var showBirthDay = $.trim($("#showBirthDay").val()); var $captcha = $("#question_captcha"); if (!checkRequired($userId)) { return; } var birthday = ""; if (showBirthDay) { birthday = $("#birthday").val(); if (birthday == '') { $(".error").text("").hide(); $("#birthday").addClass('error-border'); $("#birthday_error").text(required).show(); return; } } if (!checkRequired($captcha)) { return; } $.ajax({ type: "POST", url: "getBackPassword.do", dataType: "json", data: { userId: $.trim($userId.val()), birthday: birthday, captcha: $.trim($captcha.val()), type: "question", step: 1 }, success: function (data) { if (data.success) { $("#sign").val(data.data.sign); $("#uid").val(data.data.uid); $("#question").text(data.data.question); $("#passwordPolicy").text(data.data.passwordPolicy); $("#two").hide(); $("#three").show(); changeSh('three') $("#grxx").attr("class", "done"); $("#zjxx").attr("class", "current_prev"); $("#qzxx").attr("class", "current"); } else { captcha($(".form-two-question")); var code = data.code var message = data.message if (code == 1) {//用户名错误 showError($userId,message); return; } if (showBirthDay && code == 9) {//生日错误 $(".error").text("").hide(); $("#birthday").addClass('error-border'); $("#birthday_error").text(message).show(); return; } if (code == 3) {//验证码错误 showError($captcha,message); return; } showError($userId,message) } } }); } function validAnswer() { var uid = $("#uid").val(); var showBirthDay = $("#showBirthDay").val(); var birthday = ""; if (showBirthDay) { birthday = $("#birthday").val(); } var answer = $.trim($("#answer").val()); var sign = $("#sign").val(); if (!checkRequired($("#answer"))) { return; } $.ajax({ type: "POST", url: "getBackPassword.do", dataType: "json", data: { userId: uid, birthday: birthday, answer: answer, sign: sign, type: "question", step: 3 }, success: function (data) { if (data.success) { $("#sign").val(data.data.sign) $("#user").text(uid); $("#pwdDefaultEncryptSalt").val(data.data.pwdDefaultEncryptSalt); $("#passwordPolicy").text(data.data.passwordPolicy); $("#three").hide(); $("#four").show(); $("#grxx").attr("class", "done"); $("#zjxx").attr("class", "done"); $("#qzxx").attr("class", "current_prev"); $("#qzfs").attr("class", "current"); } else { showError($("#answer"),data.message) } } }); } function sendCode(obj) { var obj = $(obj); var uid = $("#uid").val(); var mobile = $("#mobile").val(); var sign = $("#sign").val(); $.ajax({ type: "POST", url: "getBackPassword.do", dataType: "json", data: { userId: uid, mobile: mobile, sign: sign, type: "mobile", step: 2 }, success: function (data) { if (data.success) { $(".three-p").text(data.data.msgTip).show() $("#sign").val(data.data.sign); countdown(obj) } else { var t = data.data.mobileTime; if (t != '' && t != undefined && data.data.time != -1) { time = t; countdown(obj); } $(".three-p").text(data.message).show() } } }); } function validCode() { var uid = $("#uid").val(); var mobile = $("#mobile").val(); var code = $.trim($("#code").val()); var sign = $("#sign").val(); if (!checkRequired($("#code"))) { return; } $.ajax({ type: "POST", url: "getBackPassword.do", dataType: "json", data: { userId: uid, mobile: mobile, code: code, sign: sign, type: "mobile", step: 3 }, success: function (data) { if (data.success) { $("#sign").val(data.data.sign); $("#user").text(uid); $("#passwordPolicy").text(data.data.passwordPolicy); $("#pwdDefaultEncryptSalt").val(data.data.pwdDefaultEncryptSalt); $("#three").hide(); $("#four").show(); $("#grxx").attr("class", "done"); $("#zjxx").attr("class", "done"); $("#qzxx").attr("class", "current_prev"); $("#qzfs").attr("class", "current"); } else { showError($("#code"),data.message) } } }); } function resetPassword(userId,mobile,code,birthday,answer,type) { var password = $("#password").val(); var confirmPassword = $("#confirmPassword").val(); if (!checkRequiredNoTrim($("#password"))) { return; } if (!checkRequiredNoTrim($("#confirmPassword"))) { return; } var pwdDefaultEncryptSalt = $("#pwdDefaultEncryptSalt").val(); password = encryptPassword2(password,pwdDefaultEncryptSalt); confirmPassword = encryptPassword2(confirmPassword,pwdDefaultEncryptSalt); var sign = $("#sign").val() $.ajax({ type: "POST", url: "getBackPassword.do", dataType: "json", data: { userId: userId, mobile: mobile, code: code, birthday: birthday, answer: answer, password: password, confirmPassword: confirmPassword, sign: sign, type: type, step: 4 }, success: function (data) { if (data.success) { $("#four").hide(); $("#five").show(); $("#grxx").attr("class", "done"); $("#zjxx").attr("class", "done"); $("#qzxx").attr("class", "done"); $("#qzfs").attr("class", "current_prev"); $("#finish").attr("class", "current"); goBack(3); } else { var code = data.code if (code == 6) { showError($("#confirmPassword"),data.message); return; } showError($("#password"),data.message); } } }); } function getUsername(e) { /* var $input = $(e) var user = $input.val() if (user != '123') { $input.addClass('error-border') $input.siblings('span.error').show() } else { $input.removeClass('error-border') $input.siblings('span.error').hide() }*/ } function setUserName(e) { /* var $input = $(e) $input.removeClass('error-border') $input.siblings('span.error').hide()*/ } function checkRequired(obj) { if ($.trim(obj.val()) == '') { $(".error").text("").hide(); obj.addClass('error-border'); obj.siblings('span.error').text(required).show(); return false; } obj.removeClass('error-border'); return true; } function checkRequiredNoTrim(obj) { if (obj.val() == '') { $(".error").text("").hide(); obj.addClass('error-border'); obj.siblings('span.error').text(required).show(); return false; } obj.removeClass('error-border'); return true; } function showError(obj,msg) { $(".error").text("").hide(); obj.addClass('error-border'); obj.siblings('span.error').text(msg).show(); } var time = 120; function countdown(obj) { var obj = $(obj); if (time == 0) { obj.removeAttr("disabled"); obj.removeClass("button-disabled"); obj.html(sendCodeV); time = 120; return; } else { obj.attr("disabled",true) obj.addClass("button-disabled") obj.html(time + "s") time--; } setTimeout(function () { countdown(obj) }, 1000) }