ApiUser.php 9.85 KB
<? 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"];
			
			$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"];
				
			$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 = $this->req["userPwd"];
			$userPwdConfirm=$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);
			
			if($regInfo != null)
				return $this->makeResultJson(-100, "아이디  중복을 확인해 주세요");
			
			$sql="SELECT * FROM tblUser WHERE nickName='{$nickName} AND status=1'";
			$regInfo=$this->getRow($sql);
			
			if($regInfo != null)
				return $this->makeResultJson(-101, "닉네임 중복을 확인해 주세요");
				
			if(strlen($userID)<6)
				return $this->makeResultJson(-102, "아이디는 여섯자리 이상이어야 합니다");
			
			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($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();
			/*
			$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);
		}
		
		
		// 회원 로그인 (http://106.240.232.36:8004/action_front.php?cmd=ApiUser.userLogin)
		function userLogin()
		{
			$userID = $this->req["userID"];
			$deviceID = $this->req["deviceID"];
			$deviceTypeID = $this->req["deviceTypeID"];
			$registrationKey = $this->req["registrationKey"];
			$appVersion = $this->req["appVersion"];
			
			$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"]);
				LoginUtil::doAppLogin($userInfo);
				
				return $this->makeResultJson($result[0][0]["v_returnCode"], $result[0][0]["v_returnMsg"], $userInfo);
			}
			else
			{
				return $this->makeResultJson($result[0][0]["v_returnCode"], $result[0][0]["v_returnMsg"]);
			}
		}
		
		// 비동기 푸시키 갱신 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 tbl_user
				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"];
			//$is_file_change = $this->req["is_file_change"]; // NEW / DEL / NON
			
			$userPwd = $this->req["userPwd"];
			$userPwdConfirm = $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"];
			/*
			// 삭제함
			if ($is_file_change != "NON")
			{
				$sql = "
					DELETE FROM tbl_file WHERE pa_no = '{$userNo}' AND file_type = '{$this->FILE_TYPE_MEM}'
				";
				$this->update($sql);
			}
			
			// 파일 업로드
			if ($is_file_change == "NEW" && ($_FILES != null && sizeof($_FILES) > 0))
			{
				$updateFileData = $this->inFn_Common_fileSave($_FILES);
				
				$file_vir_name = $updateFileData["file"]["saveURL"];
				$file_org_name = $updateFileData["file"]["name"];
				
				$insFile = Array(
					"file_org_name" => $file_org_name,
					"file_vir_name" => $file_vir_name,
					"reg_dt" => "now()",
					"pa_no" => $userNo,
					"file_type" => $this->FILE_TYPE_MEM
				);
				
				$fileResult = $this->techOfInsertForUpdate("tbl_file", $insFile);
			}
			*/
			$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, "비밀번호 가 일치하지 않습니다");
			
			$sql = "
				UPDATE tbl_user
				SET
					userPwd='{$userPwd}',
					userName='{$userName}',
					nickName='{$nickName}',
					userTel='{$userTel}',
					userVehicleTON='{$userVehicleTON}',
					userVehicleName='{$userVehicleName}',
					userVehicleType='{$userVehicleType}',
					userVehicleWish='{$userVehicleWish}'
				WHERE `userNo` = '{$userNo}'
			";
			$this->update($sql);

			return $this->makeResultJson("1", "저장되었습니다.", $this->inFn_ApiBase_getInfoOfUser($userNo));
		}
		
		/**
		 * 회원 정보 조회
		 */
		function getUserInfo()
		{
			$no			= $this->req["no"];
			
			$userInfo	= $this->inFn_ApiBase_getInfoOfUser($no);
			
			return $this->makeResultJson("1", "", $userInfo);
		}
		
		function delUser(){
			$userNo=$this->appUser["no"];
			
			$sql="
				UPDATE tblUser
				SET expireDate=DATE_FORMAT(NOW() + interval 3 DAY, '%Y%m%d')
				WHERE userNo='{$userNo}' AND status=1
			";
		}
		
		function delCancel(){
			$userNo=$this->appUser["no"];
			
			$sql="
				UPDATE tblUser
				SET expireDate=NULL
				WHERE userNo='{$userNo}' AND status=1
			";
		}
		
		
		
		
	} // 클래스 종료
}
?>