카카오 로그인 초기 구현

This commit is contained in:
2018-09-09 20:19:00 +09:00
parent 5b7eba61cc
commit 15d43c9653
13 changed files with 458 additions and 47 deletions
+13 -9
View File
@@ -25,7 +25,7 @@ class User_Management_Path
public static $SIGNUP = "/v1/user/signup";
public static $UNLINK = "/v1/user/unlink";
public static $LOGOUT = "/v1/user/logout";
public static $ME = "/v1/user/me";
public static $ME = "/v2/user/me";
public static $UPDATE_PROFILE = "/v1/user/update_profile";
public static $USER_IDS = "/v1/user/ids";
}
@@ -97,12 +97,12 @@ class Kakao_REST_API_Helper
$requestUrl .= '?'.$params;
}
$opts = array(
CURLOPT_URL => $requestUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSLVERSION => 1,
);
$opts = [
CURLOPT_URL => $requestUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1,
];
if ($api_path != '/oauth/token') {
if (in_array($api_path, self::$admin_apis)) {
@@ -213,8 +213,12 @@ class Kakao_REST_API_Helper
public function meWithEmail()
{
$params = [
'propertyKeys'=>'["id","kaacount_email","kaccount_email_verified"]'
];
'property_keys'=>'['.
'"id",'.
'"kakao_account.has_email","kakao_account.email",'.
'"kakao_account.is_email_valid","kakao_account.is_email_verified"'.
']'
];
return $this->request(User_Management_Path::$ME);
}
+14 -3
View File
@@ -8,12 +8,14 @@ namespace sammo;
* @property string $userName 유저명
* @property int $userGrade 유저등급
* @property string $ip IP
* @property bool $reqOTP 인증 코드 필요
* @property array $acl 권한
*/
class Session
{
const PROTECTED_NAMES = [
'ip'=>true,
'reqOTP'=>true,
'time'=>true,
'userID'=>true,
'userName'=>true,
@@ -163,7 +165,7 @@ class Session
return Util::array_get($_SESSION[$name]);
}
public function login(int $userID, string $userName, int $grade, array $acl): Session
public function login(int $userID, string $userName, int $grade, bool $reqOTP, array $acl): Session
{
$this->set('userID', $userID);
$this->set('userName', $userName);
@@ -171,10 +173,15 @@ class Session
$this->set('time', time());
$this->set('userGrade', $grade);
$this->set('acl', $acl);
$this->set('reqOTP', $reqOTP);
$this->set('access_token', null);
return $this;
}
public function setReqOTP(bool $reqOTP=false){
$this->set('reqOTP', $reqOTP);
}
public function logout(): Session
{
@@ -189,6 +196,7 @@ class Session
$this->set('userName', null);
$this->set('userGrade', null);
$this->set('acl', null);
$this->set('reqOTP', null);
$this->set('time', time());
return $this;
}
@@ -324,9 +332,12 @@ class Session
return $obj->userID;
}
public function isLoggedIn(): bool
public function isLoggedIn(bool $ignoreOTP = false): bool
{
if ($this->userID) {
if (!$ignoreOTP && $this->reqOTP){
return false;
}
else if ($this->userID) {
return true;
} else {
return false;