添加重复登录处理
This commit is contained in:
parent
f69362599e
commit
0d5882beb9
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
define('TEAMID_KEY', 'team_uuid:');
|
define('TEAMID_KEY', 'team_uuid:');
|
||||||
|
|
||||||
|
define('LAST_SESSION_KEY', 'last_session:');
|
||||||
|
|
||||||
define('V_ITEM_GOLD', 10001); //金币
|
define('V_ITEM_GOLD', 10001); //金币
|
||||||
define('V_ITEM_DIAMOND', 10002); //钻石
|
define('V_ITEM_DIAMOND', 10002); //钻石
|
||||||
define('V_ITEM_EXP', 10003); //经验
|
define('V_ITEM_EXP', 10003); //经验
|
||||||
|
@ -25,13 +25,33 @@ class BaseAuthedController extends BaseController {
|
|||||||
|
|
||||||
public function _handlePre()
|
public function _handlePre()
|
||||||
{
|
{
|
||||||
$this->accountId = $_REQUEST['account_id'];
|
$this->accountId = getReqVal('account_id', '');
|
||||||
$this->sessionId = $_REQUEST['session_id'];
|
$this->sessionId = getReqVal('session_id', '');
|
||||||
if (!phpcommon\isValidSessionId($this->accountId,
|
if (!phpcommon\isValidSessionId($this->accountId,
|
||||||
$this->sessionId)) {
|
$this->sessionId)) {
|
||||||
phpcommon\sendError(500, 'invalid session_id');
|
phpcommon\sendError(500, 'invalid session_id');
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
if (!(getReqVal('c', '') == 'User' && getReqVal('c', '') == 'login')) {
|
||||||
|
$r = $this->_getRedis($this->_getAccountId());
|
||||||
|
$sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId());
|
||||||
|
if (empty($sessionId)) {
|
||||||
|
$this->updateSession(myself()->_getAccountId(),
|
||||||
|
myself()->_getSessionId());
|
||||||
|
} else if ($sessionId != $this->_getSessionId()) {
|
||||||
|
error_log('session expiration' . json_encode(
|
||||||
|
$_REQUEST
|
||||||
|
));
|
||||||
|
phpcommon\sendError(1001, 'session expiration');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateSession($accountId, $sessionId)
|
||||||
|
{
|
||||||
|
$r = $this->_getRedis($this->_getAccountId());
|
||||||
|
$r->set(LAST_SESSION_KEY . $this->_getAccountId());
|
||||||
|
$r->pexpire(LAST_SESSION_KEY . $this->_getAccountId(), 3600 * 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function _getAccountId()
|
public function _getAccountId()
|
||||||
|
@ -24,8 +24,11 @@ class UserController extends BaseAuthedController {
|
|||||||
|
|
||||||
public function login()
|
public function login()
|
||||||
{
|
{
|
||||||
|
$this->updateSession(myself()->_getAccountId(), myself()->_getSessionId());
|
||||||
|
|
||||||
//$user_name = $_REQUEST['name'];
|
//$user_name = $_REQUEST['name'];
|
||||||
//$avatar_url = $_REQUEST['avatar_url'];
|
//$avatar_url = $_REQUEST['avatar_url'];
|
||||||
|
|
||||||
$userName = 'guest';
|
$userName = 'guest';
|
||||||
$avatarUrl = '18003';
|
$avatarUrl = '18003';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user