modify.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // 회원 정보 수정
  2. $("#fAccountModify").validate({
  3. onkeyup: false,
  4. onclick: false,
  5. onfocusout: false,
  6. showErrors: function (errorMap, errorList) {
  7. if (this.numberOfInvalids() && errorList.length > 0) {
  8. alert(errorList[0].message);
  9. $(errorList[0].element).focus();
  10. }
  11. },
  12. rules: {
  13. name: {required: true, minlength: 2, maxlength: 10, hangul: true},
  14. email: {required: true, email: true},
  15. thumb_img: {accept: "image/gif,image/jpeg,image/png"},
  16. about_me: {maxlength: 500},
  17. is_open_profile: {number: true}
  18. },
  19. messages: {
  20. name: {
  21. required: "이름을 입력해 주세요.",
  22. minlength: "이름은 최소 {0}자 이상 입니다.",
  23. maxlength: "이름은 최대 {0}자 이하 입력 가능합니다.",
  24. hangul: "이름을 한글로 입력해주세요."
  25. },
  26. email: {
  27. required: "E-mail을 입력해 주세요.",
  28. email: "E-mail 형식이 옳지 않습니다."
  29. },
  30. thumb_img: {
  31. accept: "이미지는 jpg, gif, png 형식만 첨부 가능합니다."
  32. },
  33. about_me: {
  34. maxlength: "자기소개는 최대 {0}자 이하 입력 가능합니다."
  35. },
  36. is_open_profile: {
  37. number: "정보 공개 여부 형식이 옳지 않습니다."
  38. }
  39. }
  40. });
  41. let email =
  42. {
  43. timer: null,
  44. change: function(e) {
  45. if(!confirm("이메일 소유자 인증 후 변경이 가능합니다.\n이메일 주소를 변경하시겠습니까?")) {
  46. return false;
  47. }
  48. let mail = document.getElementById("email");
  49. if (!mail.value) {
  50. mail.focus();
  51. return alert("이메일을 입력해 주세요.");
  52. }
  53. if (!validateEmail(mail.value)) {
  54. mail.focus();
  55. return alert("이메일 형식이 옳지 않습니다.");
  56. }
  57. $.ajax({
  58. url: (BASE_URL + "/account/email"),
  59. type: 'GET',
  60. data: {email: mail.value},
  61. dataType: 'json',
  62. beforeSend: function (xhr) {
  63. if (!loginCheck()) {
  64. xhr.abort();
  65. }
  66. },
  67. success: function (res) {
  68. if (res.success) {
  69. email.verify(res);
  70. } else {
  71. alert(res.message || "처리 중 오류가 발생하였습니다. 관리자에게 문의하십시오.");
  72. }
  73. },
  74. error: function (xhr, status, err) {
  75. procErrorEvent(xhr, status, err);
  76. }
  77. });
  78. e.target.blur();
  79. },
  80. verify: function(res) {
  81. document.getElementById("btnChangeEmail").setAttribute("hidden", "hidden");
  82. document.getElementById("email").className = "form-control-plaintext p-0";
  83. document.getElementById("tableRowspan").setAttribute("rowspan", 6);
  84. let $emailVerifyView = $("#emailVerifyForm");
  85. $emailVerifyView.attr("hidden", false);
  86. $emailVerifyView.find("td").html(res.view);
  87. },
  88. cancel: function() {
  89. document.getElementById("btnChangeEmail").removeAttribute("hidden");
  90. document.getElementById("email").className = "form-control";
  91. document.getElementById("tableRowspan").setAttribute("rowspan", 5);
  92. let $emailVerifyView = $("#emailVerifyForm");
  93. $emailVerifyView.attr("hidden", true);
  94. $emailVerifyView.find("td").html("");
  95. },
  96. confirm: function(e) {
  97. let code = document.getElementById("emailVerifyCode");
  98. if (!code.value) {
  99. code.focus();
  100. return alert("인증번호를 입력해 주세요.");
  101. }
  102. $.ajax({
  103. url: (BASE_URL + "/account/email/update"),
  104. type: 'POST',
  105. data: {code: code.value},
  106. dataType: 'json',
  107. beforeSend: function (xhr) {
  108. if (!loginCheck()) {
  109. xhr.abort();
  110. }
  111. },
  112. success: function (res) {
  113. if (res.success) {
  114. alert("이메일 주소가 변경되었습니다.");
  115. email.stopTimer();
  116. email.cancel();
  117. } else {
  118. alert(res.message || "처리 중 오류가 발생하였습니다. 관리자에게 문의하십시오.");
  119. }
  120. },
  121. error: function (xhr, status, err) {
  122. procErrorEvent(xhr, status, err);
  123. }
  124. });
  125. e.target.blur();
  126. },
  127. startTimer: function(setTime) {
  128. // 타이머 중복 실행 방지로 기존 시작된 타이머를 리셋하여 점점 빨라지는 오류를 방지
  129. email.stopTimer();
  130. let countDownDate = moment().add(setTime, 'seconds');
  131. this.timer = setInterval(function () {
  132. let diff = countDownDate.diff(moment());
  133. if (diff <= 0) {
  134. email.stopTimer();
  135. email.cancel();
  136. return false;
  137. } else {
  138. $("#emailVerifyExpiresAt").html(moment.utc(diff).format("mm:ss"));
  139. }
  140. });
  141. },
  142. stopTimer: function() {
  143. clearInterval(this.timer);
  144. }
  145. };
  146. let thumb = {
  147. preview: function (e) {
  148. if (e.target.files.length > 0) {
  149. let src = URL.createObjectURL(event.target.files[0]);
  150. document.getElementById("prevThumbImg").src = src;
  151. document.getElementById("btnCancelThumb").hidden = false;
  152. }else{
  153. this.cancel();
  154. }
  155. },
  156. cancel: function() {
  157. document.getElementById("prevThumbImg").src = (BASE_URL + "/images/default/default_thumb.gif");
  158. document.getElementById("btnCancelThumb").hidden = true;
  159. document.getElementById("thumbImg").value = null
  160. }
  161. };
  162. // 이메일 변경하기
  163. $(document).on("click", "#btnChangeEmail", email.change);
  164. // 이메일 인증 확인
  165. $(document).on("click", "#btnConfirmEmail", email.confirm);
  166. // 이메일 인증 취소
  167. $(document).on("click", "#btnCancelEmail", email.cancel);
  168. // 프로필 이미지 미리보기
  169. $(document).on("change", "#thumbImg", thumb.preview);
  170. // 프로필 이미지 취소
  171. $(document).on("click", "#btnCancelThumb", thumb.cancel);