You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
4.9 KiB

7 years ago
  1. APP.MEMBER = {};
  2. /**
  3. * 회원 관련 자바스크립트 초기화
  4. */
  5. APP.MEMBER.init = function() {
  6. APP.MEMBER.InitLoginForm(); // 로그인폼 init
  7. APP.MEMBER.initCheckExist();
  8. APP.MEMBER.InitRegisterForm();
  9. APP.MEMBER.InitMemberModifyForm();
  10. };
  11. APP.MEMBER.InitRegisterForm = function() {
  12. $('[data-form="form-register"]').submit(function(e) {
  13. e.preventDefault();
  14. var $form = $(this);
  15. $.ajax({
  16. type : 'PUT',
  17. data : $form.serialize(),
  18. url : base_url + '/ajax/members/info',
  19. success:function(res){
  20. if(res.result == true) {
  21. alert(LANG.member_join_success);
  22. location.href = base_url + "/members/login";
  23. }
  24. }
  25. });
  26. });
  27. };
  28. APP.MEMBER.InitMemberModifyForm = function() {
  29. $('[data-form="form-member-modify"]').submit(function(e) {
  30. e.preventDefault();
  31. var $form = $(this);
  32. $.ajax({
  33. type : 'POST',
  34. data : $form.serialize(),
  35. url : base_url + '/ajax/members/info',
  36. success:function(res){
  37. if(res.result == true) {
  38. alert(res.message);
  39. location.reload();
  40. }
  41. }
  42. });
  43. });
  44. };
  45. /**
  46. * 로그인 초기화
  47. * @constructor
  48. */
  49. APP.MEMBER.InitLoginForm = function() {
  50. $('[data-role="form-login"]').submit(function (e) {
  51. e.preventDefault();
  52. var $form = $(this);
  53. var elementLoginID = $form.find('[name="login_id"]');
  54. var elementLoginPass = $form.find('[name="login_pass"]');
  55. if(elementLoginID.val().trim() == '')
  56. {
  57. alert(LANG.member_login_userid_required);
  58. elementLoginID.focus();
  59. return false;
  60. }
  61. if(elementLoginPass.val().trim() == '')
  62. {
  63. alert(LANG.member_login_password_required);
  64. elementLoginPass.focus();
  65. return false;
  66. }
  67. $.ajax({
  68. url : base_url + 'ajax/members/login',
  69. type : "POST",
  70. data : $form.serialize(),
  71. success:function(res) {
  72. if (res.result == true) {
  73. location.href = res.reurl ? res.reurl : base_url;
  74. }
  75. },
  76. error : function(e){
  77. elementLoginPass.val('');
  78. }
  79. })
  80. });
  81. };
  82. /**
  83. * 중복확인 버튼 이벤트 연결
  84. */
  85. APP.MEMBER.initCheckExist = function() {
  86. $('[data-toggle="check-member-exist"]').each(function(){
  87. var $btn = $(this);
  88. $btn.on('click', function(){
  89. var $target = $("#" + $btn.data('target'));
  90. var key = $btn.data('check');
  91. var value = $target.val();
  92. if( typeof value == 'undefined' || ! value || ! value.trim() )
  93. {
  94. alert(LANG.member_join_user_id_required );
  95. $target.focus();
  96. return false;
  97. }
  98. var wordCheck = APP.MEMBER.denyWordCheck(key,value);
  99. if( wordCheck == 'VALID_EMAIL' )
  100. {
  101. alert(LANG.member_join_no_valid_email_address );
  102. $target.focus();
  103. return false;
  104. }
  105. else if(! wordCheck)
  106. {
  107. alert(LANG.member_join_user_id_contains_deny_word );
  108. $target.focus();
  109. return false;
  110. }
  111. if( APP.MEMBER.getInfo(key, value) )
  112. {
  113. alert(LANG.member_join_user_id_already_exists );
  114. $target.focus();
  115. return false;
  116. }
  117. alert(LANG.member_join_user_id_available );
  118. return true;
  119. });
  120. });
  121. };
  122. /**
  123. * 사용자의 정보 가져오기
  124. * @param key 가져올 기준
  125. * @param value
  126. * @returns {*}
  127. */
  128. APP.MEMBER.getInfo = function(key, value) {
  129. var info = null;
  130. $.ajax({
  131. url : base_url + '/ajax/members/info',
  132. type : 'get',
  133. async : false,
  134. cache : false,
  135. data : {
  136. key : key,
  137. value : value
  138. },
  139. success:function(res){
  140. info = res.result;
  141. }
  142. });
  143. return info;
  144. };
  145. /**
  146. * 아이디와 닉네임 금지단어 사용여부 체크
  147. * @param key 아이디/닉네임
  148. * @param value 체크할
  149. * @returns {*}
  150. */
  151. APP.MEMBER.denyWordCheck = function(key,value) {
  152. var result = null;
  153. $.ajax({
  154. url : base_url + '/ajax/members/word_check',
  155. type : 'get',
  156. async : false,
  157. cache : false,
  158. data : {
  159. key:key,
  160. value : value
  161. },
  162. success:function(res) {
  163. result = res.result;
  164. }
  165. });
  166. return result;
  167. };
  168. APP.MEMBER.POP_CHANGE_PHOTO = function() {
  169. APP.POPUP({
  170. url : '/members/photo_change',
  171. width : 600,
  172. height :150
  173. });
  174. };
  175. $(document).ready(APP.MEMBER.init);