register.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. $(function() {
  2. validateRule();
  3. $('.imgcode').click(function() {
  4. var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
  5. $(".imgcode").attr("src", url);
  6. });
  7. });
  8. $.validator.setDefaults({
  9. submitHandler: function() {
  10. register();
  11. }
  12. });
  13. function register() {
  14. $.modal.loading($("#btnSubmit").data("loading"));
  15. var username = $.common.trim($("input[name='username']").val());
  16. var password = $.common.trim($("input[name='password']").val());
  17. var validateCode = $("input[name='validateCode']").val();
  18. $.ajax({
  19. type: "post",
  20. url: ctx + "register",
  21. data: {
  22. "loginName": username,
  23. "password": password,
  24. "validateCode": validateCode
  25. },
  26. success: function(r) {
  27. if (r.code == 0) {
  28. layer.alert("<font color='red'>恭喜你,您的账号 " + username + " 注册成功!</font>", {
  29. icon: 1,
  30. title: "系统提示"
  31. },
  32. function(index) {
  33. //关闭弹窗
  34. layer.close(index);
  35. location.href = ctx + 'login';
  36. });
  37. } else {
  38. $.modal.closeLoading();
  39. $('.imgcode').click();
  40. $(".code").val("");
  41. $.modal.msg(r.msg);
  42. }
  43. }
  44. });
  45. }
  46. function validateRule() {
  47. var icon = "<i class='fa fa-times-circle'></i> ";
  48. $("#registerForm").validate({
  49. rules: {
  50. username: {
  51. required: true,
  52. minlength: 2
  53. },
  54. password: {
  55. required: true,
  56. minlength: 5
  57. },
  58. confirmPassword: {
  59. required: true,
  60. equalTo: "[name='password']"
  61. }
  62. },
  63. messages: {
  64. username: {
  65. required: icon + "请输入您的用户名",
  66. minlength: icon + "用户名不能小于2个字符"
  67. },
  68. password: {
  69. required: icon + "请输入您的密码",
  70. minlength: icon + "密码不能小于5个字符",
  71. },
  72. confirmPassword: {
  73. required: icon + "请再次输入您的密码",
  74. equalTo: icon + "两次密码输入不一致"
  75. }
  76. }
  77. })
  78. }