sso

register.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. $(function() {
  2. //获取验证码
  3. $("#get_code").click(function() {
  4. var phone = $("#phone").val();
  5. var aespass = $('#aespass').val();
  6. if (!checkPhone(phone)) {
  7. return;
  8. }
  9. var postData = {
  10. phone: phone,
  11. aespass: aespass,
  12. }
  13. $("#get_code").attr("disabled", true);
  14. changeNum(60);
  15. postRequest("/getregistcode", postData, doSuccess, doFail);
  16. function doSuccess(res) {
  17. if (res.state == 0) {
  18. serverErrorMsg(res);
  19. return;
  20. }
  21. layer.msg(res.data.msg);
  22. }
  23. });
  24. //确定
  25. $("#submit").click(function() {
  26. var code = $("#code").val();
  27. if (code != null && code != undefined && code != "") {
  28. var phone = $("#phone").val();
  29. var password = $("#password").val();
  30. if (canSure(phone, password)) {
  31. var postData = {
  32. phone: phone,
  33. password: hex_md5(password),
  34. code: code,
  35. }
  36. postRequest("/register/submit", postData, doSuccess, doFail);
  37. function doSuccess(res) {
  38. if (res.state == 0) {
  39. serverErrorMsg(res);
  40. return;
  41. }
  42. layer.msg("注册成功");
  43. window.location.href = "/org/create"; //跳转网址
  44. }
  45. } else {
  46. return;
  47. }
  48. }
  49. });
  50. document.onkeydown = function(event) {
  51. var e = event || window.event || arguments.callee.caller.arguments[0];
  52. if (e && e.keyCode == 13) { // enter 键
  53. $("#submit").click();
  54. }
  55. };
  56. });
  57. function doFail(res) {
  58. serverErrorMsg(res);
  59. }
  60. function checkPhone(phone) {
  61. if (!phone || phone == "") {
  62. layer.msg("手机号码不能为空");
  63. return false;
  64. }
  65. if (!(/^1\d{10}$/.test(phone))) {
  66. layer.msg("手机号码有误,请重填");
  67. return false;
  68. }
  69. return true;
  70. }
  71. function canSure(phone, password) {
  72. if (!phone || phone == "") {
  73. layer.msg("手机号码不能为空");
  74. return false;
  75. }
  76. if (!password) {
  77. layer.msg('密码为空');
  78. return false;
  79. }
  80. if (password.length < 6) {
  81. layer.msg('密码至少要6位数');
  82. return false;
  83. }
  84. return true;
  85. }
  86. function changeNum(num) {
  87. setTimeout(function() {
  88. if (num > 1) {
  89. $('#get_code').html(num + "s");
  90. --num;
  91. changeNum(num);
  92. } else {
  93. $('#get_code').html("发送验证码");
  94. $("#get_code").attr("disabled", false);
  95. }
  96. }, 1000);
  97. }