login_proc.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. include $_SERVER["DOCUMENT_ROOT"].'/common/lib/comm.php';
  3. $table_name = "sa_master";
  4. $mode= trim(avoid_crack($_REQUEST["mode"]));
  5. $cd_userid = trim(avoid_crack($_POST["cd_userid"]));
  6. $cd_dealerid = trim(avoid_crack($_POST["cd_dealerid"]));
  7. $nm_email = trim(avoid_crack($_POST["nm_email"]));
  8. $nm_pass = trim(avoid_crack($_POST["nm_pass"]));
  9. $ds_level = trim(avoid_crack($_POST["ds_level"]));
  10. $auto_login = trim(avoid_crack($_POST["auto_login"]));
  11. switch($mode) {
  12. case "login":
  13. $RES = array('CODE'=>'9999', 'MSG'=>'');
  14. try {
  15. if(!$_POST) {
  16. throw new Exception("정상적인 접근이 아닙니다.", "9999");
  17. }
  18. if(empty($cd_userid)) {
  19. throw new Exception("아이디가 없습니다.", "9998");
  20. }
  21. if(empty($nm_pass)) {
  22. throw new Exception("비밀번호가 없습니다.", "9997");
  23. }
  24. //소문자만 사용
  25. $cd_userid = strtolower($cd_userid);
  26. // $_whereis = " nm_email = '". $nm_email . "' and nm_pass = password('". $nm_pass ."') and ds_level = '". $ds_level ."' ";
  27. // if($_SERVER['REMOTE_ADDR'] == '220.86.24.199') {
  28. // $_whereis = " cd_userid = '". $cd_userid . "' and ds_delind = 'N' ";
  29. // }else {
  30. // $_whereis = " cd_userid = '". $cd_userid . "' and nm_pass = password('". $nm_pass ."') and ds_delind = 'N' ";
  31. // }
  32. $_whereis = " cd_userid = '". $cd_userid . "' and nm_pass = password('". $nm_pass ."') and ds_delind = 'N' ";
  33. $row = $dbCon->selectDAO("*, CONVERT(password(cd_user+nm_pass+UNIX_TIMESTAMP()), CHAR) as enc_val", $table_name, $_whereis);
  34. if (!$row['cd_userid']) {
  35. throw new Exception("로그인 정보가 정확하지 않습니다.", "9890");
  36. // echo("N");
  37. // exit;
  38. }
  39. if ($row['ds_status'] == 'W0') {
  40. throw new Exception("탈퇴한 SA 직원입니다.", "4444");
  41. }
  42. if ($row['ds_status'] == 'D0') {
  43. throw new Exception("휴면계정 SA 직원입니다.", "4445");
  44. }
  45. if ($row['ds_status'] != 'Z0') {
  46. throw new Exception("승인되지 않은 SA 직원입니다.", "4446");
  47. }
  48. // }else if ($row['ds_status'] != 'Z0') {
  49. // echo("F");
  50. // exit;
  51. // } else {
  52. $sql = "UPDATE $table_name set dt_lastlogin = now(), enc_val = '{$row['enc_val']}' where cd_user = '".$row['cd_user']."'";
  53. $result = $dbCon->query($sql);
  54. $_SESSION['s_staff_userid'] = $row['cd_userid'];
  55. $_SESSION['s_staff_user'] = $row['cd_user'];
  56. $_SESSION['s_nm_email'] = $row['nm_email'];
  57. $_SESSION['s_nm_name'] = $row['nm_name'];
  58. $_SESSION['s_nm_hp'] = $row['nm_hp'];
  59. $_SESSION['s_ds_type'] = $row['ds_type']; //$ds_type -> A0:개인,B0:업체,C0:비회원,D0:딜러,D1:딜러-관리자
  60. $_SESSION['s_ds_level'] = $row['ds_level'];
  61. $_SESSION['s_cd_user'] = $row['cd_user'];
  62. $_SESSION['s_ds_area'] = $row['ds_area'];
  63. $_SESSION['s_ds_area_sub'] = $row['ds_area_sub'];
  64. $_SESSION['s_ds_usertype'] = $row['ds_type']; //$ds_usertypeds_type 상세 사용 가능) -> A0:개인,B0:업체,C0:비회원,D0:딜러,D1:딜러-관리자 예)(($row[ds_type] == "A0")?"D0":"D1");
  65. $_SESSION['s_ds_company_bp']= $row['ds_company_bp']; //관계사
  66. $_SESSION['s_ds_branch'] = $row['ds_branch']; //지점
  67. //자동 로그인
  68. if ($auto_login == "Y"){
  69. // setAutoLogin($row['cd_user'], $dbCon);
  70. }
  71. //
  72. // echo("Y");
  73. // exit;
  74. // }
  75. $DATAS = array();
  76. $DATAS['enc_str'] = "al_usr=".$row['cd_userid']."&al_val=".$row['enc_val'];
  77. $RES['CODE'] = "0000";
  78. $RES['MSG'] = "정상.";
  79. $RES['DATAS'] = $DATAS;
  80. }catch(Exception $e){
  81. $RES['CODE'] = $e->getCode();
  82. $RES['MSG'] = $e->getMessage();
  83. }
  84. echo json_encode($RES);
  85. exit;
  86. break;
  87. case "loginAuto":
  88. $RES = array('CODE'=>'9999', 'MSG'=>'');
  89. try {
  90. if(!$_POST) {
  91. throw new Exception("정상적인 접근이 아닙니다.", "9999");
  92. }
  93. $cd_userid = trim(avoid_crack($_POST["al_usr"]));
  94. $enc_val = trim(avoid_crack($_POST["al_val"]));
  95. if(empty($cd_userid)) {
  96. throw new Exception("아이디가 없습니다.", "9998");
  97. }
  98. if(empty($enc_val)) {
  99. throw new Exception("시크릿키가 없습니다.", "9997");
  100. }
  101. $_whereis = " cd_userid = '". $cd_userid . "' and enc_val = '". $enc_val ."' and ds_delind = 'N' ";
  102. $row = $dbCon->selectDAO("*", $table_name, $_whereis);
  103. if (!$row['cd_userid']) {
  104. throw new Exception("로그인 정보가 정확하지 않습니다.", "9890");
  105. }
  106. if ($row['ds_status'] == 'D0') {
  107. throw new Exception("휴면계정 SA 직원입니다.", "4445");
  108. }
  109. if ($row['ds_status'] != 'Z0') {
  110. throw new Exception("승인되지 않은 SA 직원입니다.", "4446");
  111. }
  112. $sql = "UPDATE $table_name set dt_lastlogin = now() where cd_user = '".$row['cd_user']."'";
  113. $result = $dbCon->query($sql);
  114. $_SESSION['s_staff_userid'] = $row['cd_userid'];
  115. $_SESSION['s_staff_user'] = $row['cd_user'];
  116. $_SESSION['s_nm_email'] = $row['nm_email'];
  117. $_SESSION['s_nm_name'] = $row['nm_name'];
  118. $_SESSION['s_nm_hp'] = $row['nm_hp'];
  119. $_SESSION['s_ds_type'] = $row['ds_type']; //$ds_type -> A0:개인,B0:업체,C0:비회원,D0:딜러,D1:딜러-관리자
  120. $_SESSION['s_ds_level'] = $row['ds_level'];
  121. $_SESSION['s_cd_user'] = $row['cd_user'];
  122. $_SESSION['s_ds_area'] = $row['ds_area'];
  123. $_SESSION['s_ds_area_sub'] = $row['ds_area_sub'];
  124. $_SESSION['s_ds_usertype'] = $row['ds_type']; //$ds_usertypeds_type 상세 사용 가능) -> A0:개인,B0:업체,C0:비회원,D0:딜러,D1:딜러-관리자 예)(($row[ds_type] == "A0")?"D0":"D1");
  125. $_SESSION['s_ds_company_bp']= $row['ds_company_bp']; //관계사
  126. $_SESSION['s_ds_branch'] = $row['ds_branch']; //지점
  127. $RES['CODE'] = "0000";
  128. $RES['MSG'] = "정상.";
  129. }catch(Exception $e){
  130. $RES['CODE'] = $e->getCode();
  131. $RES['MSG'] = $e->getMessage();
  132. }
  133. echo json_encode($RES);
  134. exit;
  135. break;
  136. case "logout":
  137. $_SESSION['s_staff_userid'] = null;
  138. $_SESSION['s_staff_user'] = null;
  139. $_SESSION['s_nm_email'] = null;
  140. $_SESSION['s_nm_name'] = null;
  141. $_SESSION['s_nm_hp'] = null;
  142. $_SESSION['s_ds_type'] = null;
  143. $_SESSION['s_ds_level'] = null;
  144. $_SESSION['s_cd_user'] = null;
  145. $_SESSION['s_ds_area'] = null;
  146. $_SESSION['s_ds_area_sub'] = null;
  147. $_SESSION['s_ds_usertype'] = null;
  148. $_SESSION['s_ds_company_bp'] = null; //관계사
  149. $_SESSION['s_ds_branch'] = null; //지점
  150. setcookie ('ESMotorsStaff', '', time() - 1, "/");
  151. Redirect("/m/sa/login.php");
  152. break;
  153. default :
  154. AlertBack("지정되지않은 요청입니다");
  155. break;
  156. }
  157. //자동 로그인
  158. //db_connect $connect 넘겨주지 않고 사용해도 되나? $connect 반환 제대로 될까?
  159. function setAutoLogin($cd_user,$argDbCon){
  160. global $table_name;
  161. $_whereis1 = " cd_user = '". $cd_user . "' ";
  162. $sql1 = " select * from $table_name where cd_user = '". $cd_user . "' ";
  163. $row = mysql_fetch_array(mysql_query($sql1));
  164. setcookie ('ESMotorsStaff', 'al_usr='.$row['cd_userid'].'&al_val='.$row['enc_val'], time() + LIMIT_TIME_AUTO_LOGIN, "/");
  165. }
  166. mysql_close($connect);
  167. ?>