forgetPwd.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. var dd = dialog({contentType: 'load', skin: 'bk-popup', content: '验证中...'});
  2. var Request = new Object();
  3. Request = GetRequest();
  4. var openid = Request["openid"];
  5. var type = Number(Request["type"]);
  6. var mobile1 = Request["mobile"];
  7. var clock = "";
  8. var nums = 60;
  9. var loginParams = Request["loginParams"];
  10. var $phoneBox = $('#phoneBox');
  11. var $idcardBox = $('#idcardBox');
  12. bindEvents();
  13. if (loginParams) {
  14. loginParams = JSON.parse(decodeURIComponent(Request["loginParams"]));
  15. }
  16. $(function () {
  17. var userAgent = window.localStorage.getItem(agentName);
  18. if (userAgent) {
  19. var paurl = "";
  20. if (type == 0) {
  21. paurl = "wx/html/home/html/login.html?type=0&openid=" + openid;
  22. }
  23. else {
  24. if (mobile1) {
  25. paurl = "wx/html/home/html/login.html?type=" + type + "&openid=" + openid + "&mobile=" + mobile1;
  26. }
  27. else {
  28. paurl = "wx/html/home/html/login.html?type=" + type + "&openid=" + openid;
  29. }
  30. }
  31. //从后台那边获取签名等信息
  32. var params = {};
  33. params.pageUrl = window.location.href;
  34. $.ajax(server + "weixin/getSign", {
  35. data: params,
  36. dataType: "json",
  37. type: "post",
  38. success: function (res) {
  39. if (res.status == 200) {
  40. var t = res.data.timestamp;
  41. var noncestr = res.data.noncestr;
  42. var signature = res.data.signature;
  43. wx.config({
  44. //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  45. appId: appId, // 必填,公众号的唯一标识
  46. timestamp: t, // 必填,生成签名的时间戳
  47. nonceStr: noncestr, // 必填,生成签名的随机串
  48. signature: signature,// 必填,签名,见附录1
  49. jsApiList: [
  50. 'closeWindow'
  51. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  52. });
  53. }
  54. }
  55. });
  56. wx.ready(function () {
  57. wx.closeWindow();
  58. });
  59. }
  60. else {
  61. if (!openid) {
  62. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: 'openid获取失败'}).show();
  63. }
  64. if (mobile1) {
  65. $("#txtMobile").val(mobile1);
  66. }
  67. }
  68. })
  69. function bindEvents() {
  70. $("#checkIdCard").on("click", function () {
  71. var idcard = $('#idcardTxt').val();
  72. var data = {}
  73. if (idcard == "") {
  74. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '身份证不能为空'}).show();
  75. return;
  76. }
  77. if (!isIdcard(idcard)) {
  78. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '请输入正确的身份证号'}).show();
  79. return;
  80. }
  81. data.idCard = idcard;
  82. sendPost("weixin/getMobile", data, "json", "post", operateFailed, operateSuccesss);
  83. function operateSuccesss(res) {
  84. if (res.status == -1) {
  85. dd.close();
  86. if (res && res.msg) {
  87. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: res.msg}).show();
  88. setTimeout(function () {
  89. mui.openWindow({
  90. url: "regist-info.html",
  91. waiting: {
  92. autoShow: false, //自动显示等待框,默认为true
  93. title: '正在加载...'
  94. }
  95. });
  96. },1500)
  97. return;
  98. }
  99. } else if (res.status == -2) {
  100. dd.close();
  101. if (res && res.msg) {
  102. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '您还未绑定手机,无法重置密码,请尝试使用默认密码登录。'}).show();
  103. setTimeout(function () {
  104. mui.openWindow({
  105. url: "zhmm-login.html",
  106. waiting: {
  107. autoShow: false, //自动显示等待框,默认为true
  108. title: '正在加载...'
  109. }
  110. });
  111. },1500)
  112. }
  113. } else if (res.status == 200) {
  114. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: res.msg}).show();
  115. var mobile = res.data.mobile;
  116. var phoneNum = mobile.substring(0, 3) + "*****" + mobile.substring(8, 11);
  117. $('#txtMobile').val(mobile);
  118. $('#checkIdCard').hide().next().show();
  119. }
  120. };
  121. function operateFailed(res) {
  122. dd.close();
  123. if (res && res.msg) {
  124. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: res.msg}).show();
  125. } else {
  126. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '校验失败'}).show();
  127. }
  128. };
  129. })
  130. $("#phoneBtn").on("click", function () {
  131. if ($(this).hasClass("active")) {
  132. commit();
  133. }
  134. else{
  135. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content:'请将相关信息补充完毕'}).show();
  136. }
  137. })
  138. $("input").on("focus", function () {
  139. $(".searchbar-clear").css("pointer-events", "none").css("opacity", 0);
  140. if ($(this).val()) {
  141. $(this).next().css("pointer-events", "auto").css("opacity", 1);
  142. }
  143. }).on("input", function () {
  144. $(this).next().css("pointer-events", "auto").css("opacity", 1);
  145. });
  146. $("input").on('keyup',function(){
  147. var allHaveValue = true,
  148. a = $('input');
  149. $('input').each(function(){
  150. if(!$(this).val()) {
  151. allHaveValue = false;
  152. }
  153. });
  154. if(allHaveValue){
  155. $("#phoneBtn").addClass("active");
  156. }
  157. else{
  158. $("#phoneBtn").removeClass("active");
  159. }
  160. })
  161. $(".n-list-info").on("click", ".searchbar-clear", function () {
  162. $(this).prev().val("");
  163. $(this).css("pointer-events", "none").css("opacity", 0);
  164. $(this).prev().focus();
  165. return false;
  166. });
  167. $('#accounts').on('tap',function(){
  168. mui.openWindow({
  169. id: "account_back",
  170. url: "../../yjfk/html/account_back.html",
  171. extras: {
  172. }
  173. });
  174. })
  175. }
  176. function sendCode() {
  177. var mobile = document.getElementById("txtMobile").value;
  178. if (!mobile) {
  179. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '请先校验身份证'}).show();
  180. return;
  181. }
  182. if (!isphone(mobile)) {
  183. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '手机号格式不正确'}).show();
  184. return;
  185. }
  186. $("#messageCode1").hide();
  187. document.getElementById("message").innerHTML = nums + '秒后可重新获取';
  188. $("#messageCode2").show();
  189. clock = setInterval(doLoop, 1000); //一秒执行一次
  190. var data = {};
  191. data.mobile = mobile;
  192. data.type = 2;
  193. sendPost("common/captcha", data, "json", "post", sendFailed, sendSuccesss);
  194. }
  195. //失败
  196. function sendFailed(res) {
  197. clearInterval(clock); //清除js定时器
  198. $("#messageCode1").show();
  199. $("#messageCode2").hide();
  200. nums = 60; //重置时间
  201. if (res && res.msg) {
  202. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: res.msg}).show();
  203. } else {
  204. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '获取失败'}).show();
  205. }
  206. }
  207. function sendSuccesss(res) {
  208. if (res.status == 200) {
  209. }
  210. else {
  211. sendFailed(res);
  212. }
  213. }
  214. function doLoop() {
  215. nums--;
  216. if (nums > 0) {
  217. document.getElementById("message").innerHTML = nums + '秒后可重新获取';
  218. } else {
  219. clearInterval(clock); //清除js定时器
  220. $("#messageCode1").show();
  221. $("#messageCode2").hide();
  222. nums = 60; //重置时间
  223. }
  224. }
  225. var mobile;
  226. function commit() {
  227. mobile = document.getElementById("txtMobile").value;
  228. var captcha = document.getElementById("txtCode").value,
  229. pwd1 = $("#pwd1").val(),
  230. pwd2 = $("#pwd2").val();
  231. if (!mobile || !captcha) {
  232. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '手机号和验证码不能为空'}).show();
  233. return;
  234. }
  235. if (!isphone(mobile)) {
  236. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '手机号格式不正确'}).show();
  237. return;
  238. }
  239. if(!pwd1){
  240. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '请输入新的登录密码'}).show();
  241. return;
  242. }else{
  243. var isValid = validPwd();
  244. if(!isValid){
  245. return false;
  246. }
  247. }
  248. if(pwd1 != pwd2){
  249. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '两次输入的密码不一致!'}).show();
  250. return;
  251. }
  252. dd.showModal();
  253. //拼请求内容
  254. var data = {};
  255. data.mobile = mobile;
  256. data.captcha = captcha;
  257. data.type = 2;
  258. sendPost("common/check_captcha", data, "json", "post", operateFailed, operateSuccesss);
  259. }
  260. //失败
  261. function operateFailed(res) {
  262. dd.close();
  263. if (res && res.msg) {
  264. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: res.msg}).show();
  265. } else {
  266. dialog({contentType: 'tipsbox', bottom: true, skin: 'bk-popup', content: '验证码验证失败'}).show();
  267. }
  268. }
  269. //成功调用登录接口
  270. function operateSuccesss(res) {
  271. var idcard = $('#idcardTxt').val();
  272. if (res.status == 200) {
  273. //修改密码
  274. updatePassword();
  275. } else {
  276. //非200则为失败
  277. operateFailed(res);
  278. }
  279. }
  280. function updatePassword(){
  281. var mobile = document.getElementById("txtMobile").value,
  282. pwd1 = $("#pwd1").val(),
  283. idcard = $("#idcardTxt").val();
  284. //加密设置:获取公钥
  285. var encryURL = server + "login/public_key";
  286. var key = RSAUtils.getKeyFromServer(encryURL);
  287. //拼请求内容
  288. var data = {
  289. mobile: mobile,
  290. idcard: idcard,
  291. newpwd: RSAUtils.encryStr(key, pwd1),
  292. openid: openid,
  293. type: 1
  294. };
  295. sendPost("login/forgetpwd", data, "json", "post", operateFailed, function(res){
  296. if (res.status == 200) {
  297. dd.close();
  298. dialog({
  299. content: '重置密码成功',
  300. okValue:'确定',
  301. ok: function (){
  302. window.location.href = "login.html?type=0&openid=" + openid + "&mobile=" + mobile;
  303. }
  304. }).showModal();
  305. } else {
  306. //非200则为失败
  307. operateFailed(res);
  308. }
  309. });
  310. }
  311. var chineseReg = /.*[\u4e00-\u9fa5]+.*$/;
  312. function validPwd(){
  313. var pwd = $.trim($('#pwd1').val());
  314. if(chineseReg.test(pwd)){
  315. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'密码不可包含中文'}).show();
  316. return false;
  317. }
  318. if(pwd.length<6){
  319. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'密码不得少于6位'}).show();
  320. return false;
  321. }
  322. return pwd;
  323. }
  324. function accountShenshu(){
  325. window.location.href = "../../yjfk/html/account_back.html?type=" + type + "&openid=" + openid;
  326. }