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.

478 lines
18 KiB

7 years ago
  1. <?php
  2. /**
  3. * Class Members
  4. * -------------------------------------------
  5. * 회원 관련 페이지
  6. */
  7. class Members extends WB_Controller {
  8. public function register()
  9. {
  10. if( $this->member->is_login() ) {
  11. alert(langs('회원/login/already'), base_url("members/info"));
  12. exit;
  13. }
  14. $form_attributes['id'] = "form-register";
  15. $form_attributes['autocomplete'] = "off";
  16. $form_attributes['name'] = "form_register";
  17. $form_attributes['data-form'] = "form-register";
  18. $form_hidden_inputs['reurl'] = set_value('reurl', $this->input->get("reurl", TRUE, base_url()));
  19. $action_url = base_url( 'members/register', SSL_VERFIY ? 'https' : 'http' );
  20. $this->data['form_open'] = form_open($action_url, $form_attributes, $form_hidden_inputs);
  21. $this->data['form_close'] = form_close();
  22. $this->site->meta_title = langs('회원/register');
  23. $this->theme = $this->site->get_layout();
  24. $this->view = "members/register";
  25. }
  26. /**********************************************************
  27. * 사용자 로그인
  28. **********************************************************/
  29. public function login()
  30. {
  31. if( $this->member->is_login() ) {
  32. alert(langs('회원/login/already'), base_url("members/info"));
  33. exit;
  34. }
  35. $form_attributes['id'] = "form-login";
  36. $form_attributes['autocomplete'] = "off";
  37. $form_attributes['name'] = "form_login";
  38. $form_attributes['data-role'] = "form-login";
  39. $form_hidden_inputs['reurl'] = set_value('reurl', $this->input->get("reurl", TRUE, base_url()));
  40. $action_url = base_url( 'members/login', SSL_VERFIY ? 'https' : 'http' );
  41. $this->data['form_open'] = form_open($action_url, $form_attributes, $form_hidden_inputs);
  42. $this->data['form_close'] = form_close();
  43. $this->site->meta_title = langs('회원/signin');
  44. $this->theme = $this->site->get_layout();
  45. $this->view = "members/login";
  46. }
  47. /**********************************************************
  48. * 사용자 로그아웃
  49. **********************************************************/
  50. public function logout()
  51. {
  52. $reurl = $this->input->get("reurl", TRUE, base_url());
  53. if( get_cookie(COOKIE_AUTOLOGIN) )
  54. {
  55. $this->member->remove_autologin($this->member->is_login());
  56. }
  57. $this->session->sess_destroy();
  58. redirect( $reurl );
  59. exit;
  60. }
  61. /**********************************************************
  62. * 사용자 정보 페이지
  63. **********************************************************/
  64. public function info($page="")
  65. {
  66. if(! $this->member->is_login())
  67. {
  68. alert_login(langs('회원/login/only'));
  69. exit;
  70. }
  71. $this->data['mem'] = $this->member->info();
  72. if( $page == 'social' )
  73. {
  74. $this->info_social();
  75. }
  76. else {
  77. $this->site->meta_title = langs('회원/info/profile');
  78. $this->theme = $this->site->get_layout();
  79. $this->active = "members/info";
  80. $this->asides['member'] = "members/aside";
  81. $this->view = "members/info";
  82. }
  83. }
  84. /**********************************************************
  85. * 회원포토 변경 페이지
  86. **********************************************************/
  87. public function photo_change()
  88. {
  89. if(! $this->member->is_login())
  90. {
  91. alert_close(langs('회원/login/only'));
  92. exit;
  93. }
  94. $this->load->library('form_validation');
  95. $this->form_validation->set_rules("mem_userid", "mem_userid", "required");
  96. if( $this->form_validation->run() != FALSE )
  97. {
  98. if(! isset($_FILES) OR ! isset($_FILES['userfile']) OR ! $_FILES['userfile'] OR !isset($_FILES['userfile']['name']) OR ! $_FILES['userfile']['name'] )
  99. {
  100. alert(langs('회원/msg/change_photo_required'));
  101. exit;
  102. }
  103. // 폴더 생성
  104. make_dir(DIR_UPLOAD . DIRECTORY_SEPARATOR . "member_photo");
  105. $upload_path = DIR_UPLOAD . '/member_photo/' . date('Y') . '/' . date('m') . '/';
  106. $uploadconfig = array(
  107. 'upload_path' => "./" . $upload_path,
  108. 'allowed_types' => 'jpg|jpeg|png|gif',
  109. 'max_size' => 10 * 1024,
  110. 'encrypt_name' => true,
  111. );
  112. $this->load->library('upload');
  113. $this->upload->initialize($uploadconfig);
  114. if ($this->upload->do_upload()) {
  115. $filedata = $this->upload->data();
  116. // 기존 회원아이콘이 있다면 삭제
  117. if( $this->member->info('photo') )
  118. {
  119. if( is_file( FCPATH . $this->member->info('photo') ))
  120. {
  121. @unlink( FCPATH . $this->member->info('photo') );
  122. }
  123. }
  124. $this->db->where('mem_idx', $this->member->is_login() )->set('mem_photo', $upload_path . $filedata['file_name'])->update('member');
  125. alert_close(langs('회원/msg/change_photo_success'), TRUE);
  126. exit;
  127. }
  128. else
  129. {
  130. alert($this->upload->display_errors(' ', ' '));
  131. }
  132. }
  133. else
  134. {
  135. $this->site->meta_title = langs('회원/info/change_photo');
  136. $this->theme = $this->site->get_layout();
  137. $this->theme_file = "popup";
  138. $this->view = "members/photo_change";
  139. }
  140. }
  141. /**********************************************************
  142. * 회원정보 수정
  143. **********************************************************/
  144. public function modify()
  145. {
  146. if(! $this->member->is_login())
  147. {
  148. alert(langs('회원/login/only'));
  149. exit;
  150. }
  151. $form_attributes['id'] = "form-member-modify";
  152. $form_attributes['autocomplete'] = "off";
  153. $form_attributes['name'] = "form_member_modify";
  154. $form_attributes['data-form'] = "form-member-modify";
  155. $form_hidden_inputs['reurl'] = set_value('reurl', $this->input->get("reurl", TRUE, base_url()));
  156. $action_url = base_url( 'members/modify', SSL_VERFIY ? 'https' : 'http' );
  157. $this->data['form_open'] = form_open($action_url, $form_attributes, $form_hidden_inputs);
  158. $this->data['form_close'] = form_close();
  159. $this->site->meta_title = langs('회원/info/modify');
  160. $this->theme = $this->site->get_layout();
  161. $this->asides['member'] = "members/aside";
  162. $this->active = "members/modify";
  163. $this->view = "members/modify";
  164. }
  165. /**********************************************************
  166. * 회원 비밀번호 변경
  167. **********************************************************/
  168. public function password_change()
  169. {
  170. if(! $this->member->is_login())
  171. {
  172. alert(langs('회원/login/only'));
  173. exit;
  174. }
  175. $this->load->library('form_validation');
  176. $this->form_validation->set_rules("old_password", langs('회원/info/old_password'), "required|trim|min_length[6]|max_length[20]");
  177. $this->form_validation->set_rules("new_password", langs('회원/info/new_password'), "required|trim|min_length[6]|max_length[20]|differs[old_password]");
  178. $this->form_validation->set_rules("new_password_confirm", langs('회원/info/new_password_confirm'), "required|trim|min_length[6]|max_length[20]|matches[new_password]");
  179. if( $this->form_validation->run() != FALSE )
  180. {
  181. $current_password = $this->input->post('old_password', TRUE);
  182. $new_password = $this->input->post('new_password', TRUE);
  183. if( $this->member->info('password') != get_password_hash($current_password) )
  184. {
  185. alert(langs('회원/login/user_not_exist'));
  186. exit;
  187. }
  188. $this->db->set('mem_password', get_password_hash($new_password) );
  189. $this->db->where('mem_idx', $this->member->is_login() );
  190. $this->db->update('member');
  191. alert(langs('회원/msg/password_change_success'), base_url('members/logout') );
  192. exit;
  193. }
  194. else {
  195. $action_url = base_url('members/password_change', SSL_VERFIY ? 'https' : 'http' );
  196. $this->data['form_open'] = form_open($action_url, array('data-form'=>'form-password-change'));
  197. $this->data['form_close'] = form_close();
  198. $this->site->meta_title = langs('회원/info/password_change');
  199. $this->theme = $this->site->get_layout();
  200. $this->active = "members/password_change";
  201. $this->asides['member'] = "members/aside";
  202. $this->view = "members/password_change";
  203. }
  204. }
  205. /**********************************************************
  206. * 회원 탈퇴
  207. **********************************************************/
  208. public function withdrawals()
  209. {
  210. if(! $this->member->is_login())
  211. {
  212. alert(langs('회원/login/only'));
  213. exit;
  214. }
  215. $this->load->library('form_validation');
  216. $this->form_validation->set_rules("current_password", langs('회원/login/user_not_exist'), "required|trim|min_length[6]|max_length[20]");
  217. if( $this->form_validation->run() != FALSE )
  218. {
  219. $current_password = $this->input->post('current_password', TRUE);
  220. if( $this->member->info('password') != get_password_hash($current_password) )
  221. {
  222. alert(langs('회원/login/user_not_exist'));
  223. exit;
  224. }
  225. // 회원정보에서 삭제
  226. $this->db->where('mem_idx', $this->member->is_login() );
  227. $this->db->set('mem_status', 'N');
  228. $this->db->update('member');
  229. alert(langs('회원/msg/withdrawals_success'), base_url('members/logout') );
  230. exit;
  231. }
  232. else {
  233. $action_url = base_url('members/withdrawals', SSL_VERFIY ? 'https' : 'http' );
  234. $this->data['form_open'] = form_open($action_url, array('data-form'=>'form-withdrawals'));
  235. $this->data['form_close'] = form_close();
  236. $this->site->meta_title = langs('회원/info/withdrawals');
  237. $this->theme = $this->site->get_layout();
  238. $this->active = "members/withdrawals";
  239. $this->asides['member'] = "members/aside";
  240. $this->view = "members/withdrawals";
  241. }
  242. }
  243. /**********************************************************
  244. * 소셜 정보
  245. **********************************************************/
  246. public function info_social()
  247. {
  248. if(! $this->member->is_login())
  249. {
  250. alert_login(langs('회원/login/only'));
  251. exit;
  252. }
  253. $this->site->meta_title = langs('회원/info/social');
  254. $this->theme = $this->site->get_layout();
  255. $this->asides['member'] = "members/aside";
  256. $this->active = "members/info/social";
  257. $this->view = "members/info_social";
  258. }
  259. /**********************************************************
  260. * 소셜 로그인 처리
  261. **********************************************************/
  262. public function social_login($provider)
  263. {
  264. if(empty($provider))
  265. {
  266. alert(langs('공통/msg/invalid_access'));
  267. exit;
  268. }
  269. if(!check_social_setting($provider))
  270. {
  271. alert(strtoupper($provider) . " " . langs('회원/social/not_set') );
  272. exit;
  273. }
  274. $this->load->library("social_login_". $provider);
  275. $result = $this->{"social_login_".$provider}->get_profile();
  276. if(empty($result))
  277. {
  278. alert( langs('회원/social/failed'), base_url());
  279. }
  280. // 만약 현재 로그인 중인상태라면
  281. // 현재 아이디에 소셜로그인을 추가하는것으로 간주한다.
  282. if( $this->member->is_login() )
  283. {
  284. // 이미 등록된 소셜이 있을경우
  285. if( $social = $this->member->get_social($result['provider'], $result['id']) )
  286. {
  287. // 현재 로그인과 이미 연결되어 있는경우
  288. if( $this->member->is_login() == $social['mem_idx'] )
  289. {
  290. alert(langs('회원/social/already_linked'), base_url('members/info/social'));
  291. exit;
  292. }
  293. // 아예 다른아이디와 연결되어 있는 경우
  294. else
  295. {
  296. alert(langs('회원/social/already_another'), base_url('members/info/social'));
  297. exit;
  298. }
  299. }
  300. // 등록된 소셜이 없는경우
  301. else
  302. {
  303. // 현재 로그인과 연결설정
  304. $data['soc_provider'] = $result['provider'];
  305. $data['soc_id'] = $result['id'];
  306. $data['mem_idx'] = $this->member->is_login();
  307. $data['soc_profile'] = $result['profile'];
  308. $data['soc_gender'] = $result['gender'];
  309. $data['soc_email'] = $result['email'];
  310. $data['soc_content'] = $result['extra'];
  311. $data['soc_regtime'] = date('Y-m-d H:i:s');
  312. $this->db->insert('member_social', $data);
  313. alert(langs('회원/social/success_link'), base_url('members/info/social'));
  314. exit;
  315. }
  316. }
  317. // 현재 로그인중이 아니라면?
  318. // 새로운 아이디 생성 / 로그인 요청 으로 받아들인다.
  319. else
  320. {
  321. // 이미 등록된 소셜 계정이 있다면?
  322. if( $social = $this->member->get_social($result['provider'], $result['id']) )
  323. {
  324. $member = $this->member->get_member($social['mem_idx'], 'mem_idx');
  325. $this->member->login_process($member);
  326. redirect(base_url());
  327. }
  328. else
  329. {
  330. // 이미 등록된 이메일 주소라면
  331. if( $tmp = $this->member->get_member($result['email'], "mem_email"))
  332. {
  333. alert(langs('회원/social/already_email'), base_url());
  334. exit;
  335. }
  336. unset($tmp);
  337. $mem_userid = USE_EMAIL_ID ? $result['email'] : strtoupper(substr($result['provider'],0,1)).$result['id'];
  338. // 해당 아이디가 이미 존재하는지 확인한다.
  339. if( $tmp = $this->member->get_member($mem_userid, 'mem_userid') )
  340. {
  341. alert(langs('회원/social/already'), base_url());
  342. exit;
  343. }
  344. unset($tmp);
  345. $data['mode'] = "INSERT";
  346. $data['mem_userid'] = $mem_userid;
  347. $data['mem_password'] = $result['id'];
  348. $data['mem_nickname'] = $result['name'];
  349. $data['mem_email'] = $result['email'];
  350. $data['mem_verfy_email'] = 'Y';
  351. $data['mem_phone'] = "";
  352. $data['mem_auth'] = 1;
  353. $data['mem_gender'] = $result['gender'];
  354. $data['mem_recv_email'] = 'N';
  355. $data['mem_recv_sms'] = 'N';
  356. $this->member->info_process($data);
  357. unset($data);
  358. $member = $this->member->get_member($mem_userid, "mem_userid");
  359. $data['soc_provider'] = $result['provider'];
  360. $data['soc_id'] = $result['id'];
  361. $data['mem_idx'] = $member['mem_idx'];
  362. $data['soc_profile'] = $result['profile'];
  363. $data['soc_gender'] = $result['gender'];
  364. $data['soc_email'] = $result['email'];
  365. $data['soc_content'] = $result['extra'];
  366. $data['soc_regtime'] = date('Y-m-d H:i:s');
  367. $this->db->insert('member_social', $data);
  368. $this->member->login_process($member);
  369. redirect(base_url());
  370. exit;
  371. }
  372. }
  373. print_r($result);
  374. }
  375. /**********************************************************
  376. * 휴면 계정 전환
  377. **********************************************************/
  378. public function activation()
  379. {
  380. $this->load->library('form_validation');
  381. if( ! $this->member->is_login() )
  382. {
  383. alert(langs('공통/msg/invalid_access'));
  384. exit;
  385. }
  386. if( ! $member = $this->member->get_member( $this->member->is_login(), 'mem_idx' ) )
  387. {
  388. alert(langs('회원/login/user_not_exist'));
  389. exit;
  390. }
  391. if( $member['mem_status'] != 'H' )
  392. {
  393. alert(langs('회원/status/not_dormant'));
  394. exit;
  395. }
  396. $this->form_validation->set_rules('activation','activation','required|trim');
  397. if( $this->form_validation->run() != FALSE )
  398. {
  399. $this->db->where('mem_idx', $this->member->is_login())->set('mem_status', 'Y')->update('member');
  400. alert(langs('회원/status/activate_complete'),base_url());
  401. exit;
  402. }
  403. else {
  404. $this->site->meta_title = langs('회원/info/activation');
  405. $this->theme = $this->site->get_layout();
  406. $this->view = "members/activation";
  407. }
  408. }
  409. }