소셜로그인 클라이언트 변경하는 경우
소셜로그인 하다보면 부득이하게 소셜로그인 클라이언트 아이디를 변경하게 되는데
변경하고나면 기존 회원이 로그인이 아닌 회원가입으로 페이지 전환이 된다.
같은 이메일 주소인 경우 Identifier를 업데이트하도록 하는 로직입니다.
<code>
// plugin/social/includes/functions.php:547 추가
// 함수 내 global $g5 추가
// --- [ADD] 이메일 기반 재매핑: 클라이언트 변경으로 identifier가 바뀐 경우 병합 후 로그인 ---
if (! $is_member && !empty($user_profile)) {
// 네이버 응답: 이메일 동의가 되어 있어야 값이 온다 (emailVerified 우선)
$email = '';
if (property_exists($user_profile, 'emailVerified') && $user_profile->emailVerified) {
$email = strtolower(trim($user_profile->emailVerified));
} elseif (property_exists($user_profile, 'email') && $user_profile->email) {
$email = strtolower(trim($user_profile->email));
}
if ($email) {
// 1) 동일 이메일 회원 존재 여부
$mb = sql_fetch("SELECT mb_id, mb_email, mb_leave_date, mb_intercept_date FROM {$g5['member_table']} WHERE mb_email = '".sql_real_escape_string($email)."'");
if ($mb && $mb['mb_id'] && empty($mb['mb_leave_date']) && empty($mb['mb_intercept_date'])) {
// 2) 같은 이메일에 연결된 기존 소셜 레코드(예전 identifier)를 찾는다
$old = sql_fetch("
SELECT mp_no, provider, identifier, mb_id
FROM {$g5['social_profile_table']}
WHERE provider='naver' AND mb_id='".sql_real_escape_string($mb['mb_id'])."'
ORDER BY mp_no DESC
LIMIT 1
");
// 3) 현재 로그인 시도한 네이버의 새 identifier
$new_identifier = $user_profile->identifier; // Hybridauth profile->identifier (네이버 uid 매핑)
// 4) 이미 새 identifier로 연결되어 있다면 바로 로그인
if ($old && $old['mb_id'] && $old['identifier'] === $new_identifier) {
// 바로 로그인 처리 (기존 로직과 동일)
$mb_password = sha1( str_shuffle( "0123456789abcdefghijklmnoABCDEFGHIJ" ) );
echo social_return_from_provider_page($provider_name, $login_action_url, $mb['mb_id'], $mb_password, $url, $use_popup);
exit;
}
// 5) 다른 계정에 이미 새 identifier가 묶여 있지 않은지 방어
$dup = sql_fetch("
SELECT COUNT(*) AS cnt
FROM {$g5['social_profile_table']}
WHERE provider='naver' AND identifier='".sql_real_escape_string($new_identifier)."'
");
if (intval($dup['cnt']) > 0) {
// 동일 네이버 계정이 다른 계정에 연결된 상태 -> 충돌 안내
$msg = '동일 네이버 계정이 이미 다른 계정과 연결되어 있어 자동 병합할 수 없습니다.';
if ($use_popup == 1 || ! $use_popup) alert_close($msg); else alert($msg);
if (is_object($adapter)) social_logout_with_adapter($adapter);
exit;
}
// 6) 기존 소셜 레코드가 있으면 identifier만 새 값으로 업데이트(클라이언트 변경 대응)
if ($old && $old['mp_no']) {
sql_query("
UPDATE {$g5['social_profile_table']}
SET identifier = '".sql_real_escape_string($new_identifier)."', mp_latest_day = '".G5_TIME_YMDHIS."'
WHERE mp_no = ".intval($old['mp_no'])."
");
} else {
// 과거 소셜 레코드가 없었다면 새 레코드로 연결
// 필요한 필드만 최소 입력. 세부 프로필은 social_user_profile_replace가 갱신
sql_query("
INSERT INTO {$g5['social_profile_table']}
(mb_id, provider, identifier, mp_register_day, mp_latest_day)
VALUES
('".sql_real_escape_string($mb['mb_id'])."', 'naver', '".sql_real_escape_string($new_identifier)."', '".G5_TIME_YMDHIS."', '".G5_TIME_YMDHIS."')
");
}
// 7) 최신 프로필 저장 및 로그인
social_user_profile_replace($mb['mb_id'], $provider_name, $user_profile);
set_session('ss_social_provider', $provider_name);
// 팝업/일반 로그인 처리 동일하게 반환
$mb_password = sha1( str_shuffle( "0123456789abcdefghijklmnoABCDEFGHIJ" ) );
echo social_return_from_provider_page($provider_name, $login_action_url, $mb['mb_id'], $mb_password, $url, $use_popup);
exit;
}
}
}
// --- [END ADD] 이메일 기반 재매핑 ---
</code>
댓글 1개
감사합니다!
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4402 | ||
| 2364 | 1년 전 | 1635 | ||
| 2363 | 1년 전 | 2108 | ||
| 2362 |
디지털홍익인간
|
1년 전 | 1255 | |
| 2361 | 1년 전 | 2034 | ||
| 2360 |
parkee
|
1년 전 | 929 | |
| 2359 | 1년 전 | 1654 | ||
| 2358 | 2년 전 | 1379 | ||
| 2357 | 2년 전 | 2652 | ||
| 2356 | 2년 전 | 1651 | ||
| 2355 |
타버린나무
|
2년 전 | 1859 | |
| 2354 | 2년 전 | 2388 | ||
| 2353 |
swallow
|
2년 전 | 2362 | |
| 2352 | 2년 전 | 1511 | ||
| 2351 | 2년 전 | 1592 | ||
| 2350 |
|
2년 전 | 1479 | |
| 2349 | 2년 전 | 1291 | ||
| 2348 | 2년 전 | 2378 | ||
| 2347 | 2년 전 | 2493 | ||
| 2346 |
ceramoon
|
2년 전 | 1533 | |
| 2345 | 2년 전 | 1274 | ||
| 2344 | 2년 전 | 1678 | ||
| 2343 | 2년 전 | 2408 | ||
| 2342 | 2년 전 | 1645 | ||
| 2341 | 2년 전 | 1178 | ||
| 2340 | 2년 전 | 2529 | ||
| 2339 | 2년 전 | 1221 | ||
| 2338 | 2년 전 | 1400 | ||
| 2337 | 2년 전 | 1709 | ||
| 2336 | 2년 전 | 2003 | ||
| 2335 | 2년 전 | 2281 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기