토큰 시간 초과시 즉시 로그아웃 되도록 변경

This commit is contained in:
2018-09-10 00:22:57 +09:00
parent f996172218
commit 541d8ddd40
5 changed files with 24 additions and 18 deletions
+1
View File
@@ -52,6 +52,7 @@ $rootDB->insert('member',[
'oauth_type' => 'NONE',
'id' => $username,
'email' => null,
'token_valid_until'=>'2999-01-01 00:00:00',
'pw' => $finalPassword,
'salt' => $userSalt,
'grade'=> 6,
-8
View File
@@ -184,14 +184,6 @@ function postOAuthResult(result){
</div>
</div>
</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>
+4 -4
View File
@@ -41,7 +41,7 @@ function kakaoOAuthCheck(array $userInfo) : ?array {
$refreshTokenValidUntil = $oauthInfo['refreshTokenValidUntil']??null;
$OTPValue = $oauthInfo['OTPValue']??null;
$OTPTrialUntil = $oauthInfo['OTPTrialUntil']??null;
$tokenValidUntil = $member['token_valid_until'];
$tokenValidUntil = $userInfo['token_valid_until'];
if(!$accessToken || !$refreshToken || !$accessTokenValidUntil || !$refreshTokenValidUntil){
return [false, 'OAuth 정보가 보관되어 있지 않습니다. 카카오 로그인을 수행해 주세요.'];
@@ -97,7 +97,7 @@ function kakaoOAuthCheck(array $userInfo) : ?array {
}
$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 '.
'pw=sha2(concat(salt, %s_password, salt), 512)',[
'username'=>$username,
@@ -152,7 +152,7 @@ $RootDB->insert('member_log',[
if($userInfo['oauth_type'] == 'KAKAO'){
$oauthFailResult = kakaoOAuthCheck($userInfo);
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;
Json::die([
'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([
'result'=>true,
'reqOTP'=>false,
+2 -2
View File
@@ -174,7 +174,7 @@ if(!$tokenValidUntil || $tokenValidUntil < $now){
'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([
'result'=>false,
'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([
'result'=>true,
'reqOTP'=>false,
+17 -4
View File
@@ -10,6 +10,7 @@ namespace sammo;
* @property string $ip IP
* @property bool $reqOTP 인증 코드 필요
* @property array $acl 권한
* @property string $tokenValidUntil 로그인 토큰 길이
*/
class Session
{
@@ -23,6 +24,7 @@ class Session
'writeClosed'=>true,
'generalID'=>true,
'generalName'=>true,
'tokenValidUntil'=>true,
'acl'=>true
];
@@ -165,7 +167,7 @@ class Session
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('userName', $userName);
@@ -174,6 +176,7 @@ class Session
$this->set('userGrade', $grade);
$this->set('acl', $acl);
$this->set('reqOTP', $reqOTP);
$this->set('tokenValidUntil', $tokenValidUntil);
return $this;
}
@@ -333,10 +336,20 @@ class Session
public function isLoggedIn(bool $ignoreOTP = false): bool
{
if (!$ignoreOTP && $this->reqOTP){
return false;
if(!$ignoreOTP){
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;
} else {
return false;