Files
egbim_homepage/egbim/skin/member/basic/descope_check_email.php
T
2026-07-23 16:15:57 +09:00

159 lines
4.8 KiB
PHP

<?php
// header('Content-Type: application/json; charset=utf-8');
// ini_set('display_errors', 1);
// error_reporting(E_ALL);
// // 수신
// $email = trim($_POST['email'] ?? '');
// // $email = 'sdi9429@naver.com';
// if (!$email) {
// echo json_encode([
// 'status' => 'error',
// 'message' => '이메일이 전달되지 않았습니다.'
// ]);
// exit;
// }
// // Descope 설정
// $management_key = 'K32l5ORmzy32OvaaPvpdZsMY3JmKQb7a3vvrl10PgjlJUGk3K7EssMH3uW5VGQSbrgtEdPj'; // 예: P2w0N5fY1K...
// $project_id = 'P2wON5fy1K6kyia269VpeIzYP8oP'; // 예: PRJ-xxxx
// // API URL
// $url = 'https://api.descope.com/v1/mgmt/user?loginId=' . urlencode($email);
// // CURL 호출
// $ch = curl_init($url);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_HTTPHEADER, [
// "Authorization: Bearer {$project_id}:{$management_key}",
// "Content-Type: application/json"
// ]);
// // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
// $response = curl_exec($ch);
// $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// $curl_error = curl_error($ch);
// curl_close($ch);
// $response_json = json_decode($response, true);
// // 처리 로직
// if ($http_code === 200 && isset($response_json['user'])) {
// // 아이디가 이미 존재 (중복)
// echo json_encode([
// 'status' => 'duplicate',
// 'message' => '이미 등록된 이메일입니다.'
// ]);
// } elseif ($http_code === 404) {
// // 아이디가 존재하지 않음 (사용 가능)
// echo json_encode([
// 'status' => 'ok',
// 'message' => '사용 가능한 이메일입니다.'
// ]);
// } else {
// // 기타 오류
// echo json_encode([
// 'status' => 'error',
// 'message' => 'Descope API 호출 실패',
// 'http_code' => $http_code,
// 'error_detail' => $response_json,
// 'curl_error' => $curl_error
// ]);
// }
// exit;
?>
<?php
header('Content-Type: application/json; charset=utf-8');
ini_set('display_errors', 1);
error_reporting(E_ALL);
// 수신
$email = trim($_POST['email'] ?? '');
if (!$email) {
echo json_encode([
'status' => 'error',
'message' => '이메일이 전달되지 않았습니다.'
]);
exit;
}
// Descope 설정
$management_key = 'K32l5ORmzy32OvaaPvpdZsMY3JmKQb7a3vvrl10PgjlJUGk3K7EssMH3uW5VGQSbrgtEdPj';
$project_id = 'P2wON5fy1K6kyia269VpeIzYP8oP';
// API URL
$url = 'https://api.descope.com/v1/mgmt/user?loginId=' . urlencode($email);
// CURL 호출
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer {$project_id}:{$management_key}",
"Content-Type: application/json"
]);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
curl_close($ch);
$response_json = json_decode($response, true);
// ================================
// 존재하는 사용자일 때
// ================================
if ($http_code === 200 && isset($response_json['user'])) {
$user = $response_json["user"];
// 비밀번호 여부
$hasPassword = $user["providerInfo"]["email"]["password"] ?? false;
// 추가정보 입력 여부 (completeForm)
$completeForm = $user["customAttributes"]["completeForm"] ?? false;
// -------------------------
// 미완성 사용자 감지!!
// -------------------------
if (!$hasPassword && !$completeForm) {
echo json_encode([
'status' => 'incomplete',
'message' => '미완성 사용자입니다. 추가정보 입력이 필요합니다.',
'email' => $email
]);
exit;
}
// 완성된 사용자 → 재가입 불가
echo json_encode([
'status' => 'duplicate',
'message' => '이미 등록된 이메일입니다.'
]);
exit;
}
// ================================
// 신규 사용자 (404)
// ================================
if ($http_code === 404) {
echo json_encode([
'status' => 'ok',
'message' => '사용 가능한 이메일입니다.'
]);
exit;
}
// ================================
// 기타 오류
// ================================
echo json_encode([
'status' => 'error',
'message' => 'Descope API 호출 실패',
'http_code' => $http_code,
'error_detail' => $response_json,
'curl_error' => $curl_error
]);
exit;
?>