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.

260 lines
14 KiB

7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. require APPPATH . '/libraries/REST_Controller.php';
  4. /**************************************************************
  5. * 회원관련 API
  6. *************************************************************/
  7. class Members extends REST_Controller {
  8. function __construct()
  9. {
  10. parent::__construct();
  11. if( !$this->input->is_ajax_request() ) $this->response(array("result"=>FALSE,"message"=>langs('공통/msg/invalid_access')), 400);
  12. }
  13. /**************************************************************
  14. * 로그인 처리
  15. *************************************************************/
  16. function login_post()
  17. {
  18. if( $this->member->is_login() ) $this->response(array("result"=>FALSE,"message"=>langs('회원/login/already')), 400);
  19. $login_id = trim($this->post('login_id', TRUE));
  20. $login_pass = trim($this->post('login_pass', TRUE));
  21. $login_keep = trim($this->post('login_keep', TRUE) === 'Y') ? TRUE : FALSE;
  22. $reurl = $this->post('reurl', TRUE) ? $this->post('reurl', TRUE) : base_url();
  23. if( empty($login_id) ) $this->response(array("result"=>TRUE,"message"=>langs('회원/login/userid_required')), 400);
  24. if( empty($login_pass) ) $this->response(array("result"=>TRUE,"message"=>langs('회원/login/password_required')), 400);
  25. if( ! $info = $this->member->get_member($login_id) ) $this->response(array("result"=>TRUE,"message"=>langs('회원/login/user_not_exist')), 400);
  26. if( $info['mem_password'] != get_password_hash($login_pass) OR $info['mem_status'] == 'N' ) $this->response(array("result"=>TRUE,"message"=>langs('회원/login/user_not_exist')), 400);
  27. if( $info['mem_status'] == 'D' ) $this->response(array("result"=>TRUE,"message"=>langs('회원/login/user_denied')), 400);
  28. //if( $info['mem_status'] == 'H' ) $this->response(["result"=>TRUE,"message"=>"해당 사용자는 장기간 미접속으로 인하여 휴먼계정으로 전환된 아이디 입니다."], 400);
  29. $this->member->login_process($info, $login_keep);
  30. $this->response(array("result"=>TRUE,"message"=>langs('회원/login/success'),"reurl"=>$reurl));
  31. exit;
  32. }
  33. /**************************************************************
  34. * 사용자 정보 획득
  35. ***************************************************************/
  36. function info_get()
  37. {
  38. $key = $this->get('key', TRUE);
  39. $value = $this->get('value', TRUE);
  40. if( empty($key) ) $this->response(array("result"=>TRUE,"message"=>langs('공통/msg/invalid_access')), 400);
  41. if( empty($value) ) $this->response(array("result"=>TRUE,"message"=>langs('공통/msg/invalid_access')), 400);
  42. $member = $this->member->get_member($value, $key);
  43. $this->response(array("result"=>$member), 200);
  44. }
  45. function word_check_get()
  46. {
  47. $key = $this->get('key', TRUE);
  48. $value = $this->get('value', TRUE);
  49. if( empty($key) ) $this->response(array("result"=>TRUE,"message"=>langs('공통/msg/invalid_access')), 400);
  50. if( empty($value) ) $this->response(array("result"=>TRUE,"message"=>langs('공통/msg/invalid_access')), 400);
  51. if( $key == 'mem_userid' && USE_EMAIL_ID )
  52. {
  53. $this->load->helper('email');
  54. if( ! filter_var($value, FILTER_VALIDATE_EMAIL))
  55. {
  56. $this->response(array("result"=>'VALID_EMAIL',"message"=>langs('회원/join/no_valid_email_address')), 200);
  57. }
  58. }
  59. $deny_nickname = explode(',',$this->site->config('deny_nickname'));
  60. $deny_word = explode(',', $this->site->config('deny_word'));
  61. $deny_id = explode(',', $this->site->config('deny_id'));
  62. $deny = array();
  63. foreach($deny_nickname as $d) $deny[] = trim($d);
  64. foreach($deny_word as $d) $deny[] = trim($d);
  65. foreach($deny_id as $d) $deny[] = trim($d);
  66. $this->response(array("result"=>(! in_array($value, $deny))), 200);
  67. }
  68. /**************************************************************
  69. * 사용자 정보 추가
  70. ***************************************************************/
  71. function info_put()
  72. {
  73. $agree = trim($this->put('agree', TRUE));
  74. $mem_userid = trim($this->put('userid', TRUE));
  75. $mem_password = trim($this->put('userpass', TRUE));
  76. $mem_password_confirm = trim($this->put('userpass_confirm', TRUE));
  77. $mem_nickname = trim($this->put('usernick', TRUE));
  78. $mem_recv_email = $this->put('recv_email', TRUE) == 'Y' OR $this->put('recv_email', TRUE) == 'N' ? $this->put('recv_email', TRUE) : 'N';
  79. $mem_recv_sms = $this->put('recv_sms', TRUE) == 'Y' OR $this->put('recv_sms', TRUE) == 'N' ? $this->put('recv_sms', TRUE) : 'N';
  80. $mem_email = trim($this->put('useremail',TRUE));
  81. $mem_phone = trim($this->put('userphone', TRUE));
  82. $mem_auth = (int) $this->put('userauth', TRUE) > 0 ? (int)$this->put('userauth', TRUE) : 1;
  83. $mem_gender = ( $this->put('usergender', TRUE) == 'M' OR $this->put('usergender', TRUE) == 'F' ) ? $this->put('usergender', TRUE) : 'U';
  84. // 약관동의
  85. if( $agree !== 'Y' ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/agreement_required')), 400);
  86. // 아이디 체크
  87. $regex_email = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD';
  88. if( empty($mem_userid) ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_id_required')), 400);
  89. if( USE_EMAIL_ID ) {
  90. if( ! preg_match($regex_email, $mem_userid) ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/no_valid_email_address')), 400);
  91. $id_tmp = explode("@", $mem_userid);
  92. $id = $id_tmp[0];
  93. $mem_email = $mem_userid;
  94. }
  95. else {
  96. $id = $mem_userid;
  97. }
  98. $deny_id = explode(",", $this->site->config('deny_id'));
  99. if( in_array($id, $deny_id) ) $this->response(array("result"=>FALSE,"message"=> langs('회원/join/user_id_contains_deny_word'). " : ". $id), 400);
  100. if( $this->member->get_member($mem_userid) ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_id_already_exists')), 400);
  101. // 비밀번호 체크
  102. if( empty($mem_password) ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_password_required')), 400);
  103. if( strlen($mem_password) < 6 ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_password_min_length')), 400);
  104. if( strlen($mem_password) > 20 ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_password_max_length')), 400);
  105. // 비밀번호 확인 체크
  106. if( $mem_password != $mem_password_confirm) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_password_diffrerent')), 400);
  107. // 닉네임 체크
  108. if( empty($mem_nickname)) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_required')), 400);
  109. if( mb_strlen($mem_nickname) > 20) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_max_length')), 400);
  110. if( mb_strlen($mem_nickname) < 2) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_min_length')), 400);
  111. $deny_nickname = explode(",", $this->site->config('deny_nickname'));
  112. if( in_array($mem_nickname, $deny_nickname)) $this->response(array("result"=>FALSE,"message"=> langs('회원/join/user_nickname_contains_deny_word') ." : ". $mem_nickname), 400);
  113. if( $this->member->get_member($mem_nickname, 'mem_nickname') ) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_already_exists')), 400);
  114. // 입력시킬 데이타를 정리한다.
  115. $data['mode'] = "INSERT";
  116. $data['mem_userid'] = $mem_userid;
  117. $data['mem_password'] = get_password_hash($mem_password);
  118. $data['mem_nickname'] = $mem_nickname;
  119. $data['mem_email'] = $mem_email;
  120. $data['mem_phone'] = $mem_phone;
  121. $data['mem_auth'] = $mem_auth;
  122. $data['mem_gender'] = $mem_gender;
  123. $data['mem_verfy_email'] = USE_EMAIL_VERFY ? 'N' : 'Y';
  124. $data['mem_recv_email'] = $mem_recv_email ? $mem_recv_email : 'N';
  125. $data['mem_recv_sms'] = $mem_recv_sms? $mem_recv_sms : 'N';
  126. $data['mem_photo'] = '';
  127. if(! $this->member->info_process($data) ) {
  128. $this->response(array("result"=>FALSE,"message"=>langs('공통/msg/server_error')), 500);
  129. }
  130. else {
  131. $this->response(array("result"=>TRUE,"message"=>langs('회원/join/success')), 201);
  132. }
  133. }
  134. /**************************************************************
  135. * 사용자 정보 변경
  136. ***************************************************************/
  137. function info_post()
  138. {
  139. $mem_nickname = trim($this->post('usernick', TRUE));
  140. $mem_recv_email = $this->post('recv_email', TRUE) == 'Y' OR $this->post('recv_email', TRUE) == 'N' ? $this->post('recv_email', TRUE) : 'N';
  141. $mem_recv_sms = $this->post('recv_sms', TRUE) == 'Y' OR $this->post('recv_sms', TRUE) == 'N' ? $this->post('recv_sms', TRUE) : 'N';
  142. $mem_email = trim($this->post('useremail',TRUE));
  143. $mem_phone = trim($this->post('userphone', TRUE));
  144. $mem_gender = ( $this->post('usergender', TRUE) == 'M' OR $this->post('usergender', TRUE) == 'F' ) ? $this->post('usergender', TRUE) : 'U';
  145. // 닉네임 체크
  146. if( empty($mem_nickname)) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_required')), 400);
  147. if( mb_strlen($mem_nickname) > 20) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_max_length')), 400);
  148. if( mb_strlen($mem_nickname) < 2) $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_min_length')), 400);
  149. $deny_nickname = explode(",", $this->site->config('deny_nickname'));
  150. if( in_array($mem_nickname, $deny_nickname)) $this->response(array("result"=>FALSE,"message"=> langs('회원/join/user_nickname_contains_deny_word') ." : ". $mem_nickname), 400);
  151. if( $mem_nickname != $this->member->info('nickname') && $this->member->get_member($mem_nickname, 'mem_nickname') )
  152. $this->response(array("result"=>FALSE,"message"=>langs('회원/join/user_nickname_already_exists')), 400);
  153. // 입력시킬 데이타를 정리한다.
  154. $data['mem_nickname'] = $mem_nickname;
  155. $data['mem_email'] = $mem_email;
  156. $data['mem_phone'] = $mem_phone;
  157. $data['mem_gender'] = $mem_gender;
  158. $data['mem_recv_email'] = $mem_recv_email ? $mem_recv_email : 'N';
  159. $data['mem_recv_sms'] = $mem_recv_sms? $mem_recv_sms : 'N';
  160. $this->db->where('mem_idx', $this->member->is_login() );
  161. $this->db->update('member', $data);
  162. $this->response(array("result"=>TRUE,"message"=>langs('회원/msg/modify_success')), 200);
  163. }
  164. /**************************************************************
  165. * 사용자 상태 변경
  166. ***************************************************************/
  167. function status_post()
  168. {
  169. if(! $this->member->is_super() )
  170. $this->response(array('status'=>FALSE, 'message'=>'권한이 없습니다.'), 400);
  171. $mem_idx = $this->post('mem_idx', TRUE);
  172. $current_status = $this->post('current_status', TRUE);
  173. $change_status = $this->post('change_status', TRUE);
  174. if(empty($mem_idx))
  175. $this->response(array('status'=>FALSE, 'message'=>'관리자로 설정할 회원이 존재하지 않습니다.'), 400);
  176. if(! $mem = $this->member->get_member($mem_idx,'mem_idx') )
  177. {
  178. $this->response(array('status'=>FALSE, 'message'=>'존재하지 않는 회원입니다.'), 400);
  179. }
  180. if( $mem['mem_status'] != $current_status )
  181. {
  182. $this->response(array('status'=>FALSE, 'message'=>'변경전 회원상태가 실제 DB상 회원상태와 일치하지 않습니다.'), 400);
  183. }
  184. if( ! in_array($change_status, array('Y','N','D','H')))
  185. {
  186. $this->response(array('status'=>FALSE, 'message'=>'변경하려는 회원상태가 올바르지 않습니다.'), 400);
  187. }
  188. $this->db->trans_start();
  189. if( $change_status == 'Y' ) {
  190. $this->db->set('mem_leavetime', '0000-00-00 00:00:00');
  191. $this->db->set('mem_bantime', '0000-00-00 00:00:00');
  192. $this->db->set('mem_htime', '0000-00-00 00:00:00');
  193. }
  194. else if ($change_status == 'B') {
  195. $this->db->set('mem_bantime', date('Y-m-d H:i:s'));
  196. }
  197. else if ($change_status == 'N') {
  198. $this->db->set('mem_leavetime', date('Y-m-d H:i:s'));
  199. }
  200. else if ($change_status == 'H') {
  201. $this->db->set('mem_htime', date('Y-m-d H:i:s'));
  202. }
  203. $this->db->set('mem_status', $change_status)->where('mem_idx', $mem_idx)->update('member');
  204. if ($this->db->trans_status() === FALSE)
  205. {
  206. $this->db->trans_rollback();
  207. $this->response(array('status'=>FALSE, 'message'=>'시스템 오류가 발생하였습니다.'), 500);
  208. }
  209. else
  210. {
  211. $this->db->trans_commit();
  212. $this->response(array('status'=>TRUE, 'message'=>'회원 상태변경이 완료되었습니다.'), 200);
  213. }
  214. }
  215. }