commit
This commit is contained in:
203
kngil/bbs/join.php
Normal file
203
kngil/bbs/join.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/db_conn.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
/* =========================
|
||||
로그 함수
|
||||
========================= */
|
||||
function join_log($label, $data = null) {
|
||||
$logFile = $_SERVER['DOCUMENT_ROOT'].'/kngil/log/join.log';
|
||||
$time = date('Y-m-d H:i:s');
|
||||
|
||||
$log = "[$time] $label\n";
|
||||
if ($data !== null) {
|
||||
$log .= print_r($data, true);
|
||||
}
|
||||
$log .= "\n-----------------------------\n";
|
||||
|
||||
file_put_contents($logFile, $log, FILE_APPEND);
|
||||
}
|
||||
|
||||
/* =========================
|
||||
JSON 입력 파싱
|
||||
========================= */
|
||||
$raw = file_get_contents('php://input');
|
||||
$data = json_decode($raw, true);
|
||||
|
||||
join_log('RAW INPUT', $raw);
|
||||
join_log('PARSED DATA', $data);
|
||||
|
||||
$action = $data['action'] ?? null;
|
||||
join_log('ACTION', $action);
|
||||
|
||||
if (!$action) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Invalid action'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =================================================
|
||||
1. 아이디 중복확인
|
||||
================================================= */
|
||||
if ($action === 'check_id') {
|
||||
|
||||
$userId = trim($data['userId'] ?? '');
|
||||
join_log('CHECK_ID userId', $userId);
|
||||
|
||||
if (!preg_match('/^[a-zA-Z][a-zA-Z0-9]{3,11}$/', $userId)) {
|
||||
echo json_encode([
|
||||
'available' => false,
|
||||
'message' => '아이디 형식 오류'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT kngil.fn_user_id_check(:user_id)
|
||||
");
|
||||
$stmt->execute([':user_id' => $userId]);
|
||||
|
||||
$result = trim($stmt->fetchColumn());
|
||||
join_log('CHECK_ID RESULT', $result);
|
||||
|
||||
if (strpos($result, 'SUCCESS') === 0) {
|
||||
echo json_encode([
|
||||
'available' => true,
|
||||
'message' => '사용 가능한 아이디입니다.'
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'available' => false,
|
||||
'message' => '이미 존재하는 아이디입니다.'
|
||||
]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =================================================
|
||||
2. 회원가입
|
||||
================================================= */
|
||||
if ($action !== 'signup') {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Invalid action'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =================================================
|
||||
3. 필수값 검증
|
||||
================================================= */
|
||||
$required = ['memberType','userId','password','userName','email','phone'];
|
||||
|
||||
foreach ($required as $k) {
|
||||
if (empty($data[$k])) {
|
||||
join_log('REQUIRED MISSING', $k);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '필수 항목이 누락되었습니다.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/* =================================================
|
||||
4. 회원유형 → co_bc
|
||||
================================================= */
|
||||
$memberType = $data['memberType'] ?? '2';
|
||||
$co_bc = ($memberType === '1') ? 'CB100100' : 'CB100200';
|
||||
|
||||
join_log('co_bc', $co_bc);
|
||||
|
||||
/* =================================================
|
||||
5. 비밀번호 규칙 (8자)
|
||||
================================================= */
|
||||
if (!preg_match('/^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/', $data['password'])) {
|
||||
join_log('PASSWORD INVALID');
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '비밀번호 규칙이 올바르지 않습니다.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$userPw = $data['password'];
|
||||
|
||||
/* =================================================
|
||||
6. 이메일 검증
|
||||
================================================= */
|
||||
if (!filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
join_log('EMAIL INVALID', $data['email']);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '이메일 형식 오류'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* =================================================
|
||||
7. 프로시저 호출
|
||||
================================================= */
|
||||
try {
|
||||
|
||||
join_log('SIGNUP PARAMS', [
|
||||
'memberType' => $memberType,
|
||||
'userId' => $data['userId'],
|
||||
'userName' => $data['userName'],
|
||||
'email' => $data['email'],
|
||||
'phone' => $data['phone'],
|
||||
'company' => $data['company'] ?? null,
|
||||
'department' => $data['department'] ?? null,
|
||||
]);
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT kngil.sp_member_i(
|
||||
:p_co_bc,
|
||||
:p_member_id,
|
||||
:p_user_pw,
|
||||
:p_member_nm,
|
||||
:p_email,
|
||||
:p_tel_no,
|
||||
:p_co_nm,
|
||||
:p_dept_nm,
|
||||
:p_cid
|
||||
)
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
':p_co_bc' => $co_bc,
|
||||
':p_member_id' => $data['userId'],
|
||||
':p_user_pw' => $userPw,
|
||||
':p_member_nm' => $data['userName'],
|
||||
':p_email' => $data['email'],
|
||||
':p_tel_no' => $data['phone'],
|
||||
':p_co_nm' => $data['company'] ?? null,
|
||||
':p_dept_nm' => $data['department'] ?? null,
|
||||
':p_cid' => $data['userId']
|
||||
]);
|
||||
|
||||
$result = trim($stmt->fetchColumn());
|
||||
join_log('PROC RESULT', $result);
|
||||
|
||||
if ($result === 'SUCCESS') {
|
||||
join_log('SIGNUP SUCCESS', $data['userId']);
|
||||
echo json_encode(['success' => true]);
|
||||
} else {
|
||||
join_log('SIGNUP FAIL', $result);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (Throwable $e) {
|
||||
join_log('EXCEPTION', $e->getMessage());
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => '서버 오류'
|
||||
]);
|
||||
}
|
||||
|
||||
exit;
|
||||
Reference in New Issue
Block a user