portal html css js resource

account-binding.js 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. if(hash[url]==undefined){
  99. $(this).attr("href", "http://mail." + url);
  100. }else{
  101. $(this).attr("href", hash[url]);
  102. }
  103. }
  104. });
  105. }
  106. //判断邮箱是否绑定
  107. function userRegisterOk() {
  108. var email = $("#email").val();
  109. //console.log(email);
  110. $.ajax("/ajax/isReg?key=" + email, {
  111. type: "GET",
  112. async: false,
  113. success: function($data) {
  114. //console.log($data);
  115. if($data.data == true) {
  116. $(".msg11").text("");
  117. emailOk = true;
  118. } else {
  119. $(".msg11").text("该邮箱已绑定账号,请使用其他邮箱地址。");
  120. emailOk = false;
  121. }
  122. },
  123. error: function() {
  124. $.MsgBox.Alert('消息', '服务器请求失败')
  125. },
  126. });
  127. }
  128. var mailCode = GetQueryString('sc');
  129. //获取邮箱验证码传值注册
  130. if(mailCode != '') {
  131. $(".account-set a").eq(1).addClass("bgcolor").siblings().removeClass("bgcolor");
  132. $(".contentbox .content-set").eq(1).show().siblings().hide();
  133. $.ajax("/ajax/bindMail/" + mailCode, {
  134. type: "get",
  135. async: true,
  136. success: function(data) {
  137. userpe();
  138. },
  139. error: function() {
  140. $.MsgBox.Alert('消息提醒', '邮箱绑定失败')
  141. },
  142. data: {},
  143. dataType: 'json'
  144. });
  145. }
  146. //查询用户手机号和邮箱
  147. function userpe() {
  148. $.ajax("/ajax/qaUser", {
  149. type: "get",
  150. async: true,
  151. success: function(data) {
  152. //console.log(data)
  153. $.MsgBox.Alert('消息提醒', '邮箱绑定成功')
  154. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  155. var emaild = data.data.email;
  156. emailhome(emaild);
  157. $.cookie('userEmail', emaild, {
  158. path: "/"
  159. });
  160. $("#emailShow").text(emailCookieshow);
  161. },
  162. error: function() {
  163. $.MsgBox.Alert('消息提醒', '邮箱绑定失败')
  164. },
  165. data: {
  166. "id": $.cookie("userid")
  167. },
  168. dataType: 'json'
  169. });
  170. }
  171. //点击邮箱激活
  172. function bindEmail() {
  173. valEmail();
  174. var email = $("#email").val();
  175. if(emailPass == true && emailOk == true) {
  176. $.ajax("/ajax/reqBindMail", {
  177. type: "GET",
  178. async: false,
  179. success: function(data) {
  180. //console.log(data);
  181. if(data.success) {
  182. //console.log(data);
  183. if(data.data == true) {
  184. //$.cookie('userEmail',email);
  185. $(".cover").hide();
  186. $("#vovernext").show();
  187. $(".emalvel").text(email);
  188. } else {
  189. $.MsgBox.Alert("消息提醒", "邮箱发布失败!");
  190. }
  191. } else {
  192. $.MsgBox.Alert("消息提醒", "服务器链接超时!");
  193. }
  194. },
  195. error: function() {
  196. $.MsgBox.Alert('message', 'fail')
  197. },
  198. data: {
  199. "userid": $.cookie("userid"),
  200. "mail": $("#email").val()
  201. },
  202. dataType: 'json'
  203. });
  204. } else {
  205. /*alert("请输入正确是邮箱地址");*/
  206. }
  207. }
  208. $("#bindgo").on("click", function() {
  209. var mailVal = $('.sett').attr("href");
  210. location.href = mailVal;
  211. })
  212. //判断手机是否绑定
  213. function phoneRegisterOk() {
  214. var phoneVal = $("#phone").val();
  215. $.ajax("/ajax/isReg?key=" + phoneVal, {
  216. type: "GET",
  217. async: false,
  218. success: function($data) {
  219. //console.log($data);
  220. if($data.data == true) {
  221. $(".msg12").text("");
  222. phonePass = true;
  223. } else {
  224. $(".msg12").text("该手机已绑定账号,请使用其他手机号码。");
  225. }
  226. },
  227. error: function() {
  228. $.MsgBox.Alert('消息', '服务器请求失败')
  229. },
  230. });
  231. }
  232. //验证手机号是否合法
  233. var phonePass = false;
  234. function valPhone() {
  235. var phoneVal = $("#phone").val();
  236. var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
  237. if(hunPhone.test(phoneVal.trim())) {
  238. phoneRegisterOk();
  239. } else {
  240. phonePass = false;
  241. /*alert("手机格式正确,请输入正确的手机号码");*/
  242. $(".msg12").text("请输入正确的手机号码");
  243. }
  244. }
  245. //验证手机验证码
  246. var codePass = false;
  247. function valCode() {
  248. var phoneCode = $("#phoneCode").val();
  249. if(phoneCode.length == 0) {
  250. /*alert("请输入验证码");*/
  251. $(".msg13").text("请输入验证码");
  252. } else {
  253. if(!isNaN(phoneCode)) {
  254. codePass = true;
  255. } else {
  256. codePass = false;
  257. $(".msg13").text("请填写数字");
  258. /*alert("请填写数字");*/
  259. }
  260. }
  261. }
  262. //发送手机验证码
  263. var phoneState;
  264. function sendPhoneCode() {
  265. valPhone();
  266. if(phonePass == true) {
  267. $.ajax("/ajax/vcWithBind", {
  268. type: "GET",
  269. async: false,
  270. success: function(data) {
  271. //console.log(data);
  272. if(data.success) {
  273. if(data.data == null) {
  274. $(".msg13").text("验证码发送失败,请确认手机号码正确!");
  275. /*alert("验证码发送失败,请确认手机号码正确!");*/
  276. } else {
  277. phoneState = data.data;
  278. $(".msg13").text("发送成功,请检查验证码");
  279. }
  280. } else {
  281. $.MsgBox.Alert("消息提醒", "系统异常!");
  282. // alert("系统异常!");
  283. }
  284. },
  285. error: function() {
  286. $.MsgBox.Alert('message', 'fail')
  287. },
  288. data: {
  289. "userid": $.cookie("userid"),
  290. "mobilePhone": $("#phone").val()
  291. },
  292. dataType: 'json'
  293. });
  294. } else {
  295. /*alert("请输入正确是手机号码");*/
  296. }
  297. }
  298. //绑定手机号
  299. function bindPhone() {
  300. valCode();
  301. if(codePass == true) {
  302. /*alert($.cookie("userid"));
  303. alert($("#phone").val());
  304. alert(phoneState);
  305. alert($("#phoneCode").val());*/
  306. var phoneVal = $("#phone").val();
  307. $.ajax("/ajax/bindMobilePhone", {
  308. type: "POST",
  309. async: false,
  310. success: function(data) {
  311. if(data.success) {
  312. /*alert(2);*/
  313. if(data.data == true) {
  314. $.cookie('userMobilePhone', phoneVal, {
  315. path: "/"
  316. });
  317. $(".cover2").hide();
  318. $.MsgBox.Alert("消息提醒", "手机绑定成功!");
  319. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  320. location.reload(true);
  321. } else {
  322. $.MsgBox.Alert("消息提醒", "短信验证不正确,请检查后重新输入。");
  323. }
  324. } else {
  325. $.MsgBox.Alert("消息提醒", "系统异常!");
  326. // alert("系统异常!");
  327. }
  328. },
  329. error: function() {
  330. $.MsgBox.Alert('message', 'fail')
  331. },
  332. data: {
  333. "userid": $.cookie("userid"),
  334. "mobilePhone": $("#phone").val(),
  335. "validateCode": $("#phoneCode").val(),
  336. "state": phoneState
  337. },
  338. dataType: 'json'
  339. });
  340. } else {
  341. /*alert("请输入验证码是否正确");*/
  342. }
  343. }