140 lines
3.6 KiB
PHP
140 lines
3.6 KiB
PHP
<?php
|
|
session_start();
|
|
require_once $_SERVER['DOCUMENT_ROOT'].'/kngil/bbs/db_conn.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
// 로그인 체크
|
|
if (!isset($_SESSION['login'])) {
|
|
http_response_code(401);
|
|
echo json_encode(['status' => 'error', 'message' => '로그인이 필요합니다.']);
|
|
exit;
|
|
}
|
|
|
|
// 2차 인증 체크
|
|
if (empty($_SESSION['mypage_verified'])) {
|
|
http_response_code(403);
|
|
echo json_encode(['status' => 'error', 'message' => '마이페이지 인증이 필요합니다.']);
|
|
exit;
|
|
}
|
|
|
|
$userId = $_SESSION['login']['user_id'];
|
|
$memberId = $_SESSION['login']['member_id'];
|
|
|
|
/* ==================================================
|
|
GET : 회원정보 조회 (mypage03 열릴 때)
|
|
================================================== */
|
|
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
SELECT *
|
|
FROM kngil.sp_users_r(
|
|
:member_id,
|
|
'',
|
|
'',
|
|
'Y'
|
|
)
|
|
WHERE user_id = :user_id
|
|
LIMIT 1
|
|
");
|
|
|
|
$stmt->execute([
|
|
':member_id' => $memberId,
|
|
':user_id' => $userId
|
|
]);
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$row) {
|
|
echo json_encode(['status' => 'error', 'message' => '회원정보를 찾을 수 없습니다.']);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'data' => $row
|
|
]);
|
|
exit;
|
|
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'status' => 'error',
|
|
'message' => '조회 중 오류 발생',
|
|
'detail' => $e->getMessage()
|
|
]);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/* ==================================================
|
|
POST : 회원정보 수정
|
|
================================================== */
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
|
|
$userPw = trim($input['password'] ?? '');
|
|
$email = trim($input['email'] ?? '');
|
|
$deptNm = trim($input['dept_nm'] ?? '');
|
|
|
|
// 전화번호는 이번 단계에서 수정 안 함
|
|
$tel_no = trim($input['tel_no'] ?? '');
|
|
|
|
if ($email === '') {
|
|
echo json_encode(['status' => 'error', 'message' => '이메일은 필수입니다.']);
|
|
exit;
|
|
}
|
|
|
|
if ($userPw !== '' && strlen($userPw) < 8) {
|
|
echo json_encode(['status' => 'error', 'message' => '비밀번호는 8자 이상이어야 합니다.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
SELECT kngil.sp_users_my_u(
|
|
:user_id,
|
|
:user_pw,
|
|
:email,
|
|
:tel_no,
|
|
:dept_nm,
|
|
:mid
|
|
)
|
|
");
|
|
|
|
$stmt->execute([
|
|
':user_id' => $userId,
|
|
':user_pw' => $userPw,
|
|
':email' => $email,
|
|
':tel_no' => $tel_no,
|
|
':dept_nm' => $deptNm,
|
|
':mid' => $userId
|
|
]);
|
|
|
|
$result = $stmt->fetchColumn();
|
|
|
|
if ($result !== 'SUCCESS') {
|
|
echo json_encode(['status' => 'error', 'message' => $result]);
|
|
exit;
|
|
}
|
|
|
|
echo json_encode(['status' => 'success']);
|
|
exit;
|
|
|
|
} catch (Exception $e) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'status' => 'error',
|
|
'message' => '저장 중 오류 발생',
|
|
'detail' => $e->getMessage()
|
|
]);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// 허용되지 않은 메서드
|
|
http_response_code(405);
|
|
echo json_encode(['status' => 'error', 'message' => 'Invalid request']);
|