portal html css js resource

account-binding.js 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. //账号绑定
  2. $(function() {
  3. loginStatus();//判断个人是否登录
  4. valUser();
  5. //邮箱绑定,手机绑定,点击关闭隐藏这两个部分
  6. $(".times").click(function() {
  7. $(".cover,.coverset,.cover2").hide();
  8. });
  9. //邮箱绑定,手机绑定,点击返回,隐藏这两个部分
  10. $(".back-btn").click(function() {
  11. $(".cover").hide();
  12. $(".cover2").hide();
  13. });
  14. //这个标签已经隐藏了,点击手机账号绑定
  15. $(".replace2").click(function() {
  16. $(".cover2").show();
  17. });
  18. //这个标签已经隐藏了,点击邮箱账号绑定
  19. $(".replace1").click(function() {
  20. $(".cover").show();
  21. });
  22. //点击邮箱账号绑定
  23. $(".replace5").click(function() {
  24. $(".cover").show();
  25. })
  26. //点击手机账号绑定
  27. $(".replace6").click(function() {
  28. $(".cover2").show();
  29. });
  30. //判断是否绑定了邮箱
  31. var emailCookie = $.cookie("userEmail");
  32. var phoneCookie = $.cookie("userMobilePhone");
  33. if(emailCookie != "" && emailCookie != null && emailCookie != "null") {
  34. //alert(emailCookieshow);
  35. emailhome(emailCookie);
  36. $("#emailShow").text(emailCookieshow);
  37. $(".replace1").hide();
  38. $(".replace3").show();
  39. } else {
  40. $(".replace1").show();
  41. $(".replace3").hide();
  42. }
  43. //判断是否绑定了手机号
  44. if(phoneCookie != "" && phoneCookie != null && phoneCookie != "null") {
  45. $("#phoneShow").text(phoneCookie.substring(0, 3) + "****" + phoneCookie.substring(7, 11));
  46. $(".replace2").hide();
  47. $(".replace4").show();
  48. } else {
  49. $(".replace2").show();
  50. $(".replace4").hide();
  51. }
  52. })
  53. function emailhome(emailset) {
  54. //var emailCookieshow;
  55. var emailq = emailset.replace(/@.*/, "");
  56. var emailh = emailset.replace(emailq, "");
  57. if(emailq.length >= 6) {
  58. emailCookieshow = emailq.substring(emailq.length - 4, 0) + "****" + emailh;
  59. }
  60. if(emailq.length == 5) {
  61. emailCookieshow = emailq.substring(emailq.length - 3, 0) + "***" + emailh;
  62. }
  63. if(emailq.length == 4) {
  64. emailCookieshow = emailq.substring(emailq.length - 2, 0) + "**" + emailh;
  65. }
  66. if(emailq.length == 3) {
  67. emailCookieshow = emailq.substring(emailq.length - 1, 0) + "*" + emailh;
  68. }
  69. if(emailq.length < 3) {
  70. emailCookieshow = emailq + emailh;
  71. }
  72. return emailCookieshow;
  73. }
  74. //重新绑定邮箱
  75. var emailPass = false;
  76. var emailOk = false;
  77. //页面需要验证展示的位置,先用alert替代
  78. function valEmail() {
  79. var email = $("#email").val();
  80. //var gunf=/^\w+@\w+\.((cn)|(com)|(com\.cn))$/;
  81. var gunf = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  82. if(gunf.test(email.trim())) {
  83. userRegisterOk();
  84. emailPass = true;
  85. emailSuccess();
  86. } else {
  87. /*alert("请输入正确是邮箱地址");*/
  88. $(".msg11 span").text("请输入正确的邮箱地址。");
  89. emailPass = false;
  90. }
  91. }
  92. //获取邮箱,填写地址
  93. function emailSuccess() {
  94. var mailVal = $('#email').val();
  95. $(".sett").each(function() {
  96. var url = mailVal.split('@')[1];
  97. for(var j in hash) {
  98. $(this).attr("href", hash[url]);
  99. }
  100. });
  101. }
  102. //判断邮箱是否绑定
  103. function userRegisterOk() {
  104. var email = $("#email").val();
  105. //console.log(email);
  106. $.ajax("/ajax/isReg?key=" + email, {
  107. type: "GET",
  108. async: false,
  109. success: function($data) {
  110. //console.log($data);
  111. if($data.data == true) {
  112. $(".msg11").text("");
  113. emailOk = true;
  114. } else {
  115. $(".msg11").text("该邮箱已绑定账号,请使用其他邮箱地址。");
  116. emailOk = false;
  117. }
  118. },
  119. error: function() {
  120. $.MsgBox.Alert('消息', '服务器请求失败')
  121. },
  122. });
  123. }
  124. var mailCode = GetQueryString('sc');
  125. //获取邮箱验证码传值注册
  126. if(mailCode != '') {
  127. $(".account-set a").eq(1).addClass("bgcolor").siblings().removeClass("bgcolor");
  128. $(".contentbox .content-set").eq(1).show().siblings().hide();
  129. $.ajax("/ajax/bindMail/" + mailCode, {
  130. type: "get",
  131. async: true,
  132. success: function(data) {
  133. userpe();
  134. },
  135. error: function() {
  136. $.MsgBox.Alert('消息提醒', '邮箱绑定失败')
  137. },
  138. data: {},
  139. dataType: 'json'
  140. });
  141. }
  142. //查询用户手机号和邮箱
  143. function userpe() {
  144. $.ajax("/ajax/qaUser", {
  145. type: "get",
  146. async: true,
  147. success: function(data) {
  148. //console.log(data)
  149. $.MsgBox.Alert('消息提醒', '邮箱绑定成功')
  150. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  151. var emaild = data.data.email;
  152. emailhome(emaild);
  153. $.cookie('userEmail', emaild, {
  154. path: "/"
  155. });
  156. $("#emailShow").text(emailCookieshow);
  157. },
  158. error: function() {
  159. $.MsgBox.Alert('消息提醒', '邮箱绑定失败')
  160. },
  161. data: {
  162. "id": $.cookie("userid")
  163. },
  164. dataType: 'json'
  165. });
  166. }
  167. //点击邮箱激活
  168. function bindEmail() {
  169. valEmail();
  170. var email = $("#email").val();
  171. if(emailPass == true && emailOk == true) {
  172. $.ajax("/ajax/reqBindMail", {
  173. type: "GET",
  174. async: false,
  175. success: function(data) {
  176. //console.log(data);
  177. if(data.success) {
  178. //console.log(data);
  179. if(data.data == true) {
  180. //$.cookie('userEmail',email);
  181. $(".cover").hide();
  182. $("#vovernext").show();
  183. $(".emalvel").text(email);
  184. } else {
  185. $.MsgBox.Alert("消息提醒", "邮箱发布失败!");
  186. }
  187. } else {
  188. $.MsgBox.Alert("消息提醒", "服务器链接超时!");
  189. }
  190. },
  191. error: function() {
  192. $.MsgBox.Alert('message', 'fail')
  193. },
  194. data: {
  195. "userid": $.cookie("userid"),
  196. "mail": $("#email").val()
  197. },
  198. dataType: 'json'
  199. });
  200. } else {
  201. /*alert("请输入正确是邮箱地址");*/
  202. }
  203. }
  204. $("#bindgo").on("click", function() {
  205. var mailVal = $('.sett').attr("href");
  206. location.href = mailVal;
  207. })
  208. //判断手机是否绑定
  209. function phoneRegisterOk() {
  210. var phoneVal = $("#phone").val();
  211. $.ajax("/ajax/isReg?key=" + phoneVal, {
  212. type: "GET",
  213. async: false,
  214. success: function($data) {
  215. //console.log($data);
  216. if($data.data == true) {
  217. $(".msg12").text("");
  218. phonePass = true;
  219. } else {
  220. $(".msg12").text("该手机已绑定账号,请使用其他手机号码。");
  221. }
  222. },
  223. error: function() {
  224. $.MsgBox.Alert('消息', '服务器请求失败')
  225. },
  226. });
  227. }
  228. //验证手机号是否合法
  229. var phonePass = false;
  230. function valPhone() {
  231. var phoneVal = $("#phone").val();
  232. var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
  233. if(hunPhone.test(phoneVal.trim())) {
  234. phoneRegisterOk();
  235. } else {
  236. phonePass = false;
  237. /*alert("手机格式正确,请输入正确的手机号码");*/
  238. $(".msg12").text("请输入正确的手机号码");
  239. }
  240. }
  241. //验证手机验证码
  242. var codePass = false;
  243. function valCode() {
  244. var phoneCode = $("#phoneCode").val();
  245. if(phoneCode.length == 0) {
  246. /*alert("请输入验证码");*/
  247. $(".msg13").text("请输入验证码");
  248. } else {
  249. if(!isNaN(phoneCode)) {
  250. codePass = true;
  251. } else {
  252. codePass = false;
  253. $(".msg13").text("请填写数字");
  254. /*alert("请填写数字");*/
  255. }
  256. }
  257. }
  258. //发送手机验证码
  259. var phoneState;
  260. function sendPhoneCode() {
  261. valPhone();
  262. if(phonePass == true) {
  263. $.ajax("/ajax/vcWithBind", {
  264. type: "GET",
  265. async: false,
  266. success: function(data) {
  267. //console.log(data);
  268. if(data.success) {
  269. if(data.data == null) {
  270. $(".msg13").text("验证码发送失败,请确认手机号码正确!");
  271. /*alert("验证码发送失败,请确认手机号码正确!");*/
  272. } else {
  273. phoneState = data.data;
  274. $(".msg13").text("发送成功,请检查验证码");
  275. }
  276. } else {
  277. $.MsgBox.Alert("消息提醒", "系统异常!");
  278. // alert("系统异常!");
  279. }
  280. },
  281. error: function() {
  282. $.MsgBox.Alert('message', 'fail')
  283. },
  284. data: {
  285. "userid": $.cookie("userid"),
  286. "mobilePhone": $("#phone").val()
  287. },
  288. dataType: 'json'
  289. });
  290. } else {
  291. /*alert("请输入正确是手机号码");*/
  292. }
  293. }
  294. //绑定手机号
  295. function bindPhone() {
  296. valCode();
  297. if(codePass == true) {
  298. /*alert($.cookie("userid"));
  299. alert($("#phone").val());
  300. alert(phoneState);
  301. alert($("#phoneCode").val());*/
  302. var phoneVal = $("#phone").val();
  303. $.ajax("/ajax/bindMobilePhone", {
  304. type: "POST",
  305. async: false,
  306. success: function(data) {
  307. if(data.success) {
  308. /*alert(2);*/
  309. if(data.data == true) {
  310. $.cookie('userMobilePhone', phoneVal, {
  311. path: "/"
  312. });
  313. $(".cover2").hide();
  314. $.MsgBox.Alert("消息提醒", "手机绑定成功!");
  315. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  316. location.reload(true);
  317. } else {
  318. $.MsgBox.Alert("消息提醒", "短信验证不正确,请检查后重新输入。");
  319. }
  320. } else {
  321. $.MsgBox.Alert("消息提醒", "系统异常!");
  322. // alert("系统异常!");
  323. }
  324. },
  325. error: function() {
  326. $.MsgBox.Alert('message', 'fail')
  327. },
  328. data: {
  329. "userid": $.cookie("userid"),
  330. "mobilePhone": $("#phone").val(),
  331. "validateCode": $("#phoneCode").val(),
  332. "state": phoneState
  333. },
  334. dataType: 'json'
  335. });
  336. } else {
  337. /*alert("请输入验证码是否正确");*/
  338. }
  339. }