sso

login_by_code.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. $(function() {
  2. var cachedMobile = getCookie("login_mobile");
  3. if (cachedMobile != null) {
  4. $("#phone").val(cachedMobile);
  5. }
  6. //获取验证码
  7. $("#get_code").click(function() {
  8. var phone = $("#phone").val();
  9. var aespass = $('#aespass').val();
  10. if (!checkPhone(phone)) {
  11. return;
  12. }
  13. var postData = {
  14. phone: phone,
  15. aespass: aespass,
  16. }
  17. $("#get_code").attr("disabled", true);
  18. changeNum(60);
  19. postRequest("/getcode", postData, doSuccess, doFail);
  20. function doSuccess(res) {
  21. if (res.state == 0) {
  22. serverErrorMsg(res);
  23. return;
  24. }
  25. layer.msg(res.data.msg);
  26. }
  27. });
  28. //确定
  29. $("#submit").click(function() {
  30. var code = $("#code").val();
  31. if (code != null && code != undefined && code != "") {
  32. var mobile = $("#phone").val();
  33. if (checkPhone(mobile)) {
  34. var postData = {
  35. mobile: mobile,
  36. code: code,
  37. returnurl: $("#return_url").val(),
  38. app_type: $("#app_type").val(),
  39. }
  40. setCookie("login_mobile", mobile);
  41. postRequest("/login/code/submit", postData, doSuccess, doFail);
  42. function doSuccess(res) {
  43. if (res.state == 0) {
  44. serverErrorMsg(res);
  45. return;
  46. }
  47. var url = res.data.url;
  48. window.location.href = url;
  49. }
  50. }
  51. }
  52. });
  53. document.onkeydown = function(event) {
  54. var e = event || window.event || arguments.callee.caller.arguments[0];
  55. if (e && e.keyCode == 13) { // enter 键
  56. $("#submit").click();
  57. }
  58. };
  59. });
  60. function doFail(res) {
  61. serverErrorMsg(res);
  62. }
  63. function checkPhone(phone) {
  64. if (!phone || phone == "") {
  65. layer.msg("手机号码不能为空");
  66. return false;
  67. }
  68. if (!(/^1\d{10}$/.test(phone))) {
  69. layer.msg("手机号码有误,请重填");
  70. return false;
  71. }
  72. return true;
  73. }
  74. function changeNum(num) {
  75. setTimeout(function() {
  76. if (num > 1) {
  77. $('#get_code').html(num + "s");
  78. --num;
  79. changeNum(num);
  80. } else {
  81. $('#get_code').html("发送验证码");
  82. $("#get_code").attr("disabled", false);
  83. }
  84. }, 1000);
  85. }
  86. function setCookie(name,value){
  87. document.cookie = name + "="+ escape (value) + ";expires=" + 0;
  88. }
  89. function getCookie(name){
  90. var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  91. if (arr != null)
  92. return unescape(arr[2]);
  93. return null;
  94. }