sso

login.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. $(function() {
  2. var cachedMobile = getCookie("login_mobile");
  3. if (cachedMobile != null) {
  4. $("#phone").val(cachedMobile);
  5. }
  6. //确定
  7. $("#submit").click(function() {
  8. var mobile = $("#phone").val();
  9. var password = $("#password").val();
  10. if (canSure(mobile, password)) {
  11. var postData = {
  12. mobile: mobile,
  13. password: hex_md5(password),
  14. returnurl: $("#return_url").val(),
  15. app_type: $("#app_type").val(),
  16. }
  17. setCookie("login_mobile", mobile);
  18. postRequest("/login/submit", postData, doSuccess, doFail);
  19. function doSuccess(res) {
  20. if (res.state == 0) {
  21. serverErrorMsg(res);
  22. return;
  23. }
  24. var url = res.data.url;
  25. window.location.href = url;
  26. }
  27. } else {
  28. return;
  29. }
  30. });
  31. document.onkeydown = function(event) {
  32. var e = event || window.event || arguments.callee.caller.arguments[0];
  33. if (e && e.keyCode == 13) { // enter 键
  34. $("#submit").click();
  35. }
  36. };
  37. });
  38. function doFail(res) {
  39. serverErrorMsg(res);
  40. }
  41. function checkPhone(phone) {
  42. if (!phone || phone == "") {
  43. layer.msg("手机号码不能为空");
  44. return false;
  45. }
  46. if (!(/^1\d{10}$/.test(phone))) {
  47. layer.msg("手机号码有误,请重填");
  48. return false;
  49. }
  50. return true;
  51. }
  52. function canSure(phone, password) {
  53. if (!checkPhone(phone)) {
  54. return false;
  55. }
  56. if (!password) {
  57. layer.msg('密码为空');
  58. return false;
  59. }
  60. if (password.length < 6) {
  61. layer.msg('密码至少要6位数');
  62. return false;
  63. }
  64. return true;
  65. }
  66. function setCookie(name,value){
  67. document.cookie = name + "="+ escape (value) + ";expires=" + 0;
  68. }
  69. function getCookie(name){
  70. var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  71. if (arr != null)
  72. return unescape(arr[2]);
  73. return null;
  74. }