122 lines
4.1 KiB
PHP
122 lines
4.1 KiB
PHP
<?php
|
|
require_once dirname(__DIR__, 4) . '/auth/common.php';
|
|
|
|
auth_session_start_if_needed();
|
|
|
|
$email = trim($_POST['mb_id'] ?? '');
|
|
$password = trim($_POST['mb_password'] ?? '');
|
|
|
|
|
|
if (!$email || !$password) {
|
|
echo json_encode(['status'=>'fail', 'message'=>'아이디와 비밀번호는 필수입력입니다.']);
|
|
exit;
|
|
}
|
|
|
|
$descope_project_id = "P2wON5fy1K6kyia269VpeIzYP8oP";
|
|
|
|
$api_url = "https://api.descope.com/v1/auth/password/signin";
|
|
|
|
$data = [
|
|
"loginId" => $email,
|
|
"password" => $password,
|
|
// "loginOptions" => [ ... ] // 옵션 필요시
|
|
];
|
|
$headers = [
|
|
'Content-Type: application/json',
|
|
'Authorization: Bearer ' . $descope_project_id,
|
|
];
|
|
|
|
$ch = curl_init($api_url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
$response = curl_exec($ch);
|
|
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
$res_data = json_decode($response, true);
|
|
|
|
if ($http_code === 200 && isset($res_data['sessionJwt'])) {
|
|
// 로그인 성공 → 실패횟수 초기화
|
|
$_SESSION['login_fail_count'] = 0;
|
|
//session으로도 저장
|
|
$normalizedUser = auth_apply_user_session(
|
|
$res_data['user'] ?? [],
|
|
'descope',
|
|
[
|
|
'sessionJwt' => $res_data['sessionJwt'] ?? '',
|
|
'refreshJwt' => $res_data['refreshJwt'] ?? '',
|
|
]
|
|
);
|
|
setcookie('baron_user', '', auth_cookie_options(time() - 42000));
|
|
setcookie('baron_claims', '', auth_cookie_options(time() - 42000));
|
|
setcookie('baron_provider', '', auth_cookie_options(time() - 42000));
|
|
auth_set_descope_session_cookies($normalizedUser);
|
|
|
|
echo json_encode([
|
|
'status' => 'ok',
|
|
'sessionJwt' => $res_data['sessionJwt'] ?? '',
|
|
// 'refreshJwt' => $res_data['refreshJwt'] ?? '',
|
|
'user' => $normalizedUser,
|
|
'session' => $_SESSION,
|
|
]);
|
|
// } else {
|
|
// // $msg = $res_data['errorDescription'] ?? '로그인 실패';
|
|
// // echo json_encode(['status'=>'fail', 'message'=>$msg]);
|
|
// // Descope 에러 메시지
|
|
// $errorMsg = $res_data['errorDescription']
|
|
// ?? $res_data['errorMessage']
|
|
// ?? '로그인에 실패했습니다.';
|
|
|
|
// // 2) 한글 매핑
|
|
// if (stripos($errorMsg, 'invalid signin credentials') !== false) {
|
|
// $msg = '비밀번호가 일치하지 않습니다.';
|
|
// } elseif (stripos($errorMsg, 'user not found') !== false) {
|
|
// $msg = "계정을 찾을 수 없습니다.\n로그인에 문제가 있으신 경우 010-8721-7453으로 문의해 주세요.";
|
|
// } else {
|
|
// $msg = $errorMsg;
|
|
// }
|
|
|
|
|
|
// echo json_encode([
|
|
// 'status' => 'fail',
|
|
// 'message' => $msg
|
|
// ]);
|
|
// }
|
|
} else {
|
|
// 실패 → 카운트 증가
|
|
if (!isset($_SESSION['login_fail_count'])) {
|
|
$_SESSION['login_fail_count'] = 0;
|
|
}
|
|
$_SESSION['login_fail_count']++;
|
|
$failCount = $_SESSION['login_fail_count'];
|
|
|
|
// 에러 메시지 가공
|
|
$errorMsg = $res_data['errorDescription']
|
|
?? $res_data['errorMessage']
|
|
?? '로그인에 실패했습니다.';
|
|
|
|
// 한글 매핑
|
|
if (stripos($errorMsg, 'Login is temporarily locked') !== false) {
|
|
$msg = "Login is temporarily locked. Please try again later.";
|
|
} elseif (stripos($errorMsg, 'account locked') !== false) {
|
|
$msg = "Your account has been locked due to too many login attempts.\nPlease contact the administrator.";
|
|
} elseif (stripos($errorMsg, 'invalid signin credentials') !== false) {
|
|
$msg = "The password does not match.";
|
|
} elseif (stripos($errorMsg, 'user not found') !== false) {
|
|
$msg = "The account could not be found.\nIf you are experiencing login issues, please contact +82-2-2141-7434";
|
|
} else {
|
|
$msg = $errorMsg;
|
|
}
|
|
|
|
echo json_encode([
|
|
'status' => 'fail',
|
|
'message' => $msg,
|
|
'failCount' => $failCount
|
|
]);
|
|
}
|
|
exit;
|
|
?>
|