6cdb84358a38159f86d60a6e67830ec2eaf3a2f3.svn-base 12.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
<? include $_SERVER["DOCUMENT_ROOT"] . "/common/classes/ApiBase.php" ;?>
<?

/*
 * Admin process
 * add by dev.lee
 */
if (! class_exists("ApiUser"))
{

	class ApiUser extends ApiBase
	{

		function __construct($req)
		{
			parent::__construct($req);
		} 
				
		// 회원가입 여부 판단 (http://106.240.232.36:8004/action_front.php?cmd=ApiUser.initLogin&id=aa)
		function initLogin()
		{
			$userID = $this->req["userID"];
			
			$sql = "
				SELECT userID 
				FROM tblUser 
				WHERE userID='{$userID}' AND status=1 
				LIMIT 0,1 
			";
			
			$userID = $this->getValue($sql, "userID");
			
			$returnCode = - 1;
			if ($userID != "")
			{
				$returnCode = 1;
			}
			
			return $this->makeResultJson($returnCode, "");
		}
		
		function removeSpecials($string){
			return preg_replace("/[ #\&\+\-%@=\/\\\:;,\.'\"\^`~\_|\!\?\*$#<>()\[\]\{\}]/i", "", $string);
		}
		
		function checkIDRedundancy(){
			$userID=$this->req["userID"];
			
			if($userID == "")
				return $this->makeResultJson(-1, "아이디 입력 후 시도해 주세요");
			
			$sql="
				SELECT *
				FROM tblUser
				WHERE userID='{$userID}' AND status=1
				LIMIT 0, 1
			";
			$result=$this->getRow($sql);
			
			if($result != null)
				return $this->makeResultJson(-100, "사용할 수 없는 아이디 입니다");
			else 
				return $this->makeResultJson(1, "사용할 수 있는 아이디 입니다");
		}
		
		function checkNickRedundancy(){
			$nickName=$this->req["nickName"];
			
			if($nickName == "")
				return $this->makeResultJson(-1, "닉네임 입력 후 시도해 주세요");
			
			$sql="
			SELECT *
			FROM tblUser
			WHERE nickName='{$nickName}' AND status=1
			LIMIT 0, 1
			";
			$result=$this->getRow($sql);
				
			if($result != null)
				return $this->makeResultJson(-100, "사용할 수 없는 닉네임 입니다");
				else
					return $this->makeResultJson(1, "사용할 수 있는 닉네임 입니다");
		}
		
		
		
		// 회원 가입 (http://106.240.232.36:8004/action_front.php?cmd=ApiUser.memberJoin)
		function memberJoin()
		{
			$userID = $this->req["userID"];
			$userPwd = md5($this->req["userPwd"]);
			$userPwdConfirm=md5($this->req["userPwdConfirm"]);
			$userName = $this->req["userName"];
			$nickName = $this->req["nickName"];
			$userTel = str_replace(" ", "", $this->req["userTel"]);
			$userVehicleTON=$this->req["userVehicleTON"];
			$userVehicleName=$this->req["userVehicleName"];
			$userVehicleType=$this->req["userVehicleType"];
			$userVehicleWish=$this->req["userVehicleWish"];
			$deviceTypeID = $this->req["deviceTypeID"];
			$deviceID = $this->req["deviceID"];
			$registrationKey = $this->req["registrationKey"];
			$appVersion = $this->req["appVersion"];
			
			//if($nickName=="")
				//$nickName=$userName;
			// $status = ($memType == this.MEM_TYPE_NOMAL) ? "" : "" ;

			$sql = "
				SELECT * 
				FROM tblUser
				WHERE `userID` = '{$userID}' AND `status` = 1
				LIMIT 1
			";
			$regInfo = $this->getRow($sql);
			//return json_encode($regInfo);
			
			if(strlen($userID) < 6){
				return $this->makeResultJson(-106, "아이디는 여섯 자리 이상이어야 합니다.");
			}
			
			if(strlen($userID) != strlen($this->removeSpecials($userID))) {
				return $this->makeResultJson(-108, "아이디에는 특수문자가 포함될 수 없습니다.");
			}
			
			if($regInfo != NULL)
				return $this->makeResultJson(-100, "아이디  중복을 확인해 주세요.", $regInfo);
			
			if($nickName == NULL)
				return $this->makeResultJson(-107, "닉네임을 입력해 주세요");
				
			$sql="SELECT * FROM tblUser WHERE nickName='{$nickName} AND status=1'";
			$regInfo=$this->getRow($sql);
			
			if($regInfo != NULL)
				return $this->makeResultJson(-101, "닉네임 중복을 확인해 주세요.", $regInfo);
							
			if(strlen($userPwd) != strlen($this->removeSpecials($userPwd))) {
				return $this->makeResultJson(-103, "비밀번호에는 특수문자가 포함될 수 없습니다.");
			}
			else if(strlen($userPwd) < 4)
				return $this->makeResultJson(-104, "비밀번호는 네 자리 이상이어야 합니다.");
			
			if($userPwd != $userPwdConfirm)
				return $this->makeResultJson(-105, "비밀번호가 일치하지 않습니다.");
			
			if($userName == "")
				return $this->makeResultJson(-102, "이름을 입력해 주세요.");
			/*
			if($userTel == "")
				return $this->makeResultJson(-105, "전화번호는 필수 입력사항입니다.");
			*/
				

			$insAssoc = Array(
				"userType"=>1,
				"userID" => $userID,
				"userPwd"=> $userPwd,
				"userName" => $userName,
				"nickName" => $nickName,
				"userTel" => $userTel,
				"userVehicleTON" => $userVehicleTON,
				"userVehicleName" => $userVehicleName,
				"userVehicleType" => $userVehicleType,
				"userVehicleWish" => $userVehicleWish,
				"deviceTypeID" => $deviceTypeID,
				"deviceID" => $deviceID,
				"registrationKey" => $registrationKey,
				"push" => 1,
				"appVersion" => $appVersion,
				"lastLoginDate"=>"now()",
				"status" => 1,
				"regDate" => "now()"
			);
			
			$result = $this->techOfInsertForUpdate("tblUser", $insAssoc);
			
			$no = $this->mysql_insert_id();
			
			$userInfo = $this->inFn_ApiBase_getInfoOfUser($no);
			/*
			$file_vir_name = "";
			$file_org_name = "";
			
			if ($this->MEM_REGI_EMAIL == $regiType)
			{
				$updateFileData = $this->inFn_Common_fileSave($_FILES);
				
				$file_vir_name = $updateFileData["file"]["saveURL"];
				$file_org_name = $updateFileData["file"]["name"];
			}
			else
			{
				$file_vir_name = $this->req["fileName"];
			}
			
			$insFile = Array(
				"file_org_name" => $file_org_name,
				"file_vir_name" => $file_vir_name,
				"reg_dt" => "now()",
				"pa_no" => $no,
				"file_type" => "ME"
			);
			
			$fileResult = $this->techOfInsertForUpdate("tbl_file", $insFile);
			*/
			if ($result > 0)
			{
				$returnCode = "1";
				$returnMessage = "가입되었습니다.";
			}
			else
			{
				$returnCode = "-1";
				$returnMessage = "오류가 발생했습니다.";
			}
			
			return $this->makeResultJson($returnCode, $returnMessage, $userInfo);
		}
		
		function checkExpire($userNo, $expireDate){
// 			echo date('Y-m-d', strtoTime($expireDate));
			if($expireDate!=null && date('Y-m-d', strtotime($expireDate)) <= date('Y-m-d')){
				$sql="
				UPDATE tblUser
				SET status=0
				WHERE userNo='{$userNo}'
				";
				$this->update($sql);
				return 1;
			}
		}
		
		// 회원 로그인 (http://106.240.232.36:8004/action_front.php?cmd=ApiUser.userLogin)
		function userLogin()
		{
			$userID = $this->req["userID"];
			$userPwd= md5($this->req["userPwd"]);
			$deviceID = $this->req["deviceID"];
			$deviceTypeID = $this->req["deviceTypeID"];
			$registrationKey = $this->req["registrationKey"];
			$appVersion = $this->req["appVersion"];
			
			$res="";
			
			$param = Array(
				$userID,
				$deviceID,
				$deviceTypeID,
				$registrationKey,
				$appVersion
			);
			
			$sql = $this->strCallProc3("uspU_loginUser", $param);

			$result = $this->getMultiArray($sql);
			
			if ($result[0][0]["v_returnCode"] > 0)
			{
				$userInfo = $this->inFn_ApiBase_getInfoOfUser($result[0][0]["v_userNumber"]);
				//echo $userPwd;
				//echo $userInfo["userID"];
				if($userInfo["expireDate"]!=null)
					$res=$this->checkExpire($userInfo["userNo"], $userInfo["expireDate"]);
					
// 				echo $res;
				
				if($res==1)
					return $this->makeResultJson(-999, "탈퇴된 회원입니다");
				
				if($userInfo["userPwd"] != $userPwd)
					return $this->makeResultJson("-1000", "비밀번호를 확인하세요", $userInfo["userPwd"]);
				
				LoginUtil::doAppLogin($userInfo);
				
				
				return $this->makeResultJson($result[0][0]["v_returnCode"], $result[0][0]["v_returnMsg"], $userInfo);
// 				return $this->makeResultJson($result[0][0]["v_returnCode"], $result[0][0]["v_returnMsg"], $this->appUser);
			}
			else
			{
				return $this->makeResultJson($result[0][0]["v_returnCode"], $result[0][0]["v_returnMsg"]);
			}
		}
		
		function userAutoLogin(){
			$userNo=$this->req["userNo"];
			$userID = $this->req["userID"];
			$deviceID = $this->req["deviceID"];
			$deviceTypeID = $this->req["deviceTypeID"];
			$registrationKey = $this->req["registrationKey"];
			$appVersion = $this->req["appVersion"];
			$userPwd=md5($this->req["userPwd"]);
			
			$res="";
			
			$sql="SELECT expireDate FROM tblUser WHERE userNo='{$userNo}' AND status=1 LIMIT 1";
			$expireDate=$this->getValue($sql, "expireDate");
			
			if($expireDate!=NULL)
				$res=$this->checkExpire($userNo, $expireDate);
			
			if($res==1)
				return $this->makeResultJson(-999, "탈퇴된 회원입니다");
			
			$param = Array(
				$userNo,
				$deviceID,
				$deviceTypeID,
				$registrationKey,
				$appVersion,
				$userPwd
			);
			
			$result=$this->inFn_ApiBase_autoLogin($param);

			return $this->makeResultJson($result["isLogin"], $result["loginMessage"], $result["loginInfo"]);
			
		}
		
		
		// 비동기 푸시키 갱신 API
		function setUserRegistrationKey()
		{
			$userNo = $this->appUser["no"];
			$registrationKey = $this->req["registrationKey"];
			
			if ($no != "-1")
			{
				$sql = "
					UPDATE tblUser
					SET registrationKey = '{$registrationKey}'
					WHERE userNo = '{$userNo}'
				";
				$this->update($sql);
			}
		}
		
		// 푸시 설정
		function setPushOnOff()
		{
			$userNo = $this->appUser["no"];
			$push = $this->req["push"];
			
			$sql = "
				UPDATE tblUser
				SET push = '{$push}'
				WHERE `userNo` = '{$userNo}'
			";
			$result = $this->update($sql);
			
			return $this->makeResultJson("1", "");
		}
	
		// 로그아웃
		function userLogout()
		{
			$userNo = $this->appUser["no"];
			
			// 푸시키 초기화
			$sql = "
				UPDATE tblUser
				SET registrationKey = ''
				WHERE userNo = '{$userNo}'
			";
			$this->update($sql);
			
			return $this->makeResultJson("1", "");
		}
		
		// 정보수정
		function modifyUserInfo()
		{
			$userNo = $this->appUser["no"];
// 			$userNo=$this->req["userNo"];
			
			$userPwd = $this->req["userPwd"];
			$userPwdConfirm = $this->req["userPwdConfirm"];
			$nickName = $this->req["nickName"];
			$userTel = str_replace(" ", "", $this->req["userTel"]);
			$userVehicleTON=$this->req["userVehicleTON"];
			$userVehicleName=$this->req["userVehicleName"];
			$userVehicleType=$this->req["userVehicleType"];
			$userVehicleWish=$this->req["userVehicleWish"];
			
			$sql="SELECT nickName FROM tblUser WHERE userNo='{$userNo}'";
			$currentNick=$this->getValue($sql, "nickName");
// 			echo "currentNick".$currentNick;
// 			echo "changeNick".$nickName;
			
			if($currentNick != $nickName){
				//echo "???";
				$sql="SELECT * FROM tblUser WHERE nickName='{$nickName}' AND status=1";
				$regInfo=$this->getRow($sql);
				if($regInfo != null)
					return $this->makeResultJson(-100, "닉네임 중복을 확인해 주세요");
						
			}
			
			if($userPwd != $userPwdConfirm)
				return $this->makeResultJson(-101, "비밀번호 가 일치하지 않습니다");
			
			$userPwd=md5($userPwd);
			
			if($userPwd==""){
				$sql = "
				UPDATE tblUser
				SET
				nickName='{$nickName}',
				userTel='{$userTel}',
				userVehicleTON='{$userVehicleTON}',
				userVehicleName='{$userVehicleName}',
				userVehicleType='{$userVehicleType}',
				userVehicleWish='{$userVehicleWish}'
				WHERE `userNo` = '{$userNo}'
				";
				$this->update($sql);
			}
			else{
				$sql = "
				UPDATE tblUser
				SET
				userPwd='{$userPwd}',
				nickName='{$nickName}',
				userTel='{$userTel}',
				userVehicleTON='{$userVehicleTON}',
				userVehicleName='{$userVehicleName}',
				userVehicleType='{$userVehicleType}',
				userVehicleWish='{$userVehicleWish}'
				WHERE `userNo` = '{$userNo}'
				";
				$this->update($sql);
			}
			
			$userInfo = $this->inFn_ApiBase_getInfoOfUser($userNo);
			
			return $this->makeResultJson("1", "저장되었습니다.", $userInfo);
		}
		
		/**
		 * 회원 정보 조회
		 */
		function getUserInfo()
		{
			$no			= $this->req["no"];
			
			$userInfo	= $this->inFn_ApiBase_getInfoOfUser($no);
			
			return $this->makeResultJson("1", "", $userInfo);
		}
		
		function delUser(){
			$userNo=$this->appUser["no"];
			//$userNo=$this->req["no"];
			$sql="
				UPDATE tblUser
				SET expireDate=DATE_FORMAT(NOW() + interval 3 DAY, '%Y%m%d')
				WHERE userNo='{$userNo}' AND status=1
			";
			$this->update($sql);
			return $this->makeResultJson("1", "탈퇴 신청이 완료되었습니다");
		}
		
		function delCancel(){
// 			$userNo=$this->appUser["no"];
			$userNo=$this->req["userNo"];
			$sql="
				UPDATE tblUser
				SET expireDate=NULL
				WHERE userNo='{$userNo}' AND status=1
			";
			$this->update($sql);
			return $this->makeResultJson("1", "취소되었습니다");
		}
		
		
		
		
	} // 클래스 종료
}
?>