토큰 시간 초과시 즉시 로그아웃 되도록 변경
This commit is contained in:
@@ -52,6 +52,7 @@ $rootDB->insert('member',[
|
|||||||
'oauth_type' => 'NONE',
|
'oauth_type' => 'NONE',
|
||||||
'id' => $username,
|
'id' => $username,
|
||||||
'email' => null,
|
'email' => null,
|
||||||
|
'token_valid_until'=>'2999-01-01 00:00:00',
|
||||||
'pw' => $finalPassword,
|
'pw' => $finalPassword,
|
||||||
'salt' => $userSalt,
|
'salt' => $userSalt,
|
||||||
'grade'=> 6,
|
'grade'=> 6,
|
||||||
|
|||||||
@@ -184,14 +184,6 @@ function postOAuthResult(result){
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<!--
|
|
||||||
<div class="form-group row">
|
|
||||||
<div class="col-sm-4"><a href="javascript:getOAuthToken('change_pw', 'talk_message');">비밀번호 찾기<img src="oauth_kakao/kakao_to_me.png"></a></div>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+4
-4
@@ -41,7 +41,7 @@ function kakaoOAuthCheck(array $userInfo) : ?array {
|
|||||||
$refreshTokenValidUntil = $oauthInfo['refreshTokenValidUntil']??null;
|
$refreshTokenValidUntil = $oauthInfo['refreshTokenValidUntil']??null;
|
||||||
$OTPValue = $oauthInfo['OTPValue']??null;
|
$OTPValue = $oauthInfo['OTPValue']??null;
|
||||||
$OTPTrialUntil = $oauthInfo['OTPTrialUntil']??null;
|
$OTPTrialUntil = $oauthInfo['OTPTrialUntil']??null;
|
||||||
$tokenValidUntil = $member['token_valid_until'];
|
$tokenValidUntil = $userInfo['token_valid_until'];
|
||||||
|
|
||||||
if(!$accessToken || !$refreshToken || !$accessTokenValidUntil || !$refreshTokenValidUntil){
|
if(!$accessToken || !$refreshToken || !$accessTokenValidUntil || !$refreshTokenValidUntil){
|
||||||
return [false, 'OAuth 정보가 보관되어 있지 않습니다. 카카오 로그인을 수행해 주세요.'];
|
return [false, 'OAuth 정보가 보관되어 있지 않습니다. 카카오 로그인을 수행해 주세요.'];
|
||||||
@@ -97,7 +97,7 @@ function kakaoOAuthCheck(array $userInfo) : ?array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$userInfo = $RootDB->queryFirstRow(
|
$userInfo = $RootDB->queryFirstRow(
|
||||||
'SELECT `no`, `id`, `name`, `grade`, `delete_after`, `acl`, oauth_id, oauth_type, oauth_info '.
|
'SELECT `no`, `id`, `name`, `grade`, `delete_after`, `acl`, oauth_id, oauth_type, oauth_info, token_valid_until '.
|
||||||
'from member where id=%s_username AND '.
|
'from member where id=%s_username AND '.
|
||||||
'pw=sha2(concat(salt, %s_password, salt), 512)',[
|
'pw=sha2(concat(salt, %s_password, salt), 512)',[
|
||||||
'username'=>$username,
|
'username'=>$username,
|
||||||
@@ -152,7 +152,7 @@ $RootDB->insert('member_log',[
|
|||||||
if($userInfo['oauth_type'] == 'KAKAO'){
|
if($userInfo['oauth_type'] == 'KAKAO'){
|
||||||
$oauthFailResult = kakaoOAuthCheck($userInfo);
|
$oauthFailResult = kakaoOAuthCheck($userInfo);
|
||||||
if($oauthFailResult !== null){
|
if($oauthFailResult !== null){
|
||||||
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], true, Json::decode($userInfo['acl']??'{}'));
|
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], true, $userInfo['token_valid_until'], Json::decode($userInfo['acl']??'{}'));
|
||||||
[$oauthReqOTP, $oauthFailReason] = $oauthFailResult;
|
[$oauthReqOTP, $oauthFailReason] = $oauthFailResult;
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>false,
|
'result'=>false,
|
||||||
@@ -163,7 +163,7 @@ if($userInfo['oauth_type'] == 'KAKAO'){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], false, Json::decode($userInfo['acl']??'{}'));
|
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], false, $userInfo['token_valid_until'], Json::decode($userInfo['acl']??'{}'));
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>true,
|
'result'=>true,
|
||||||
'reqOTP'=>false,
|
'reqOTP'=>false,
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ if(!$tokenValidUntil || $tokenValidUntil < $now){
|
|||||||
'reason'=>'인증 코드를 보내는데 실패했습니다.'
|
'reason'=>'인증 코드를 보내는데 실패했습니다.'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], true, Json::decode($userInfo['acl']??'{}'));
|
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], true, $userInfo['token_valid_until'], Json::decode($userInfo['acl']??'{}'));
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>false,
|
'result'=>false,
|
||||||
'reqOTP'=>true,
|
'reqOTP'=>true,
|
||||||
@@ -192,7 +192,7 @@ $RootDB->insert('member_log',[
|
|||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], false, Json::decode($userInfo['acl']??'{}'));
|
$session->login($userInfo['no'], $userInfo['id'], $userInfo['grade'], false, $userInfo['token_valid_until'], Json::decode($userInfo['acl']??'{}'));
|
||||||
Json::die([
|
Json::die([
|
||||||
'result'=>true,
|
'result'=>true,
|
||||||
'reqOTP'=>false,
|
'reqOTP'=>false,
|
||||||
|
|||||||
+17
-4
@@ -10,6 +10,7 @@ namespace sammo;
|
|||||||
* @property string $ip IP
|
* @property string $ip IP
|
||||||
* @property bool $reqOTP 인증 코드 필요
|
* @property bool $reqOTP 인증 코드 필요
|
||||||
* @property array $acl 권한
|
* @property array $acl 권한
|
||||||
|
* @property string $tokenValidUntil 로그인 토큰 길이
|
||||||
*/
|
*/
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
@@ -23,6 +24,7 @@ class Session
|
|||||||
'writeClosed'=>true,
|
'writeClosed'=>true,
|
||||||
'generalID'=>true,
|
'generalID'=>true,
|
||||||
'generalName'=>true,
|
'generalName'=>true,
|
||||||
|
'tokenValidUntil'=>true,
|
||||||
'acl'=>true
|
'acl'=>true
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -165,7 +167,7 @@ class Session
|
|||||||
return Util::array_get($_SESSION[$name]);
|
return Util::array_get($_SESSION[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login(int $userID, string $userName, int $grade, bool $reqOTP, array $acl): Session
|
public function login(int $userID, string $userName, int $grade, bool $reqOTP, ?string $tokenValidUntil, array $acl): Session
|
||||||
{
|
{
|
||||||
$this->set('userID', $userID);
|
$this->set('userID', $userID);
|
||||||
$this->set('userName', $userName);
|
$this->set('userName', $userName);
|
||||||
@@ -174,6 +176,7 @@ class Session
|
|||||||
$this->set('userGrade', $grade);
|
$this->set('userGrade', $grade);
|
||||||
$this->set('acl', $acl);
|
$this->set('acl', $acl);
|
||||||
$this->set('reqOTP', $reqOTP);
|
$this->set('reqOTP', $reqOTP);
|
||||||
|
$this->set('tokenValidUntil', $tokenValidUntil);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,10 +336,20 @@ class Session
|
|||||||
|
|
||||||
public function isLoggedIn(bool $ignoreOTP = false): bool
|
public function isLoggedIn(bool $ignoreOTP = false): bool
|
||||||
{
|
{
|
||||||
if (!$ignoreOTP && $this->reqOTP){
|
if(!$ignoreOTP){
|
||||||
return false;
|
if($this->reqOTP){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!$this->tokenValidUntil){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$now = TimeUtil::DatetimeNow();
|
||||||
|
if($this->tokenValidUntil < $now){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ($this->userID) {
|
|
||||||
|
if ($this->userID) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user