/** * 用户授权管理:撤销 access token 授权 */ public function vRevokeToken($iUid, $iCid, $sToken) { $tokenApi = $this->_aConf['tokenApi']; $oOption = new Ko_Tool_SQL(); $oOption->oWhere('uid = ? and cid = ?', $iUid, $iCid); $this->{$tokenApi}->iDelete($sToken, $oOption); }
public function aGetRoleList($iStart, $iLength, $flag = null) { $option = new Ko_Tool_SQL(); $option->oOffset($iStart)->oLimit($iLength)->oCalcFoundRows(true); $option->oOrderBy('ctime desc'); if (is_int($flag)) { $option->oWhere('flag = ?', $flag); } $aData = $this->aGetList($option); $aResult['total'] = $option->iGetFoundRows(); $aResult['list'] = $aData; return $aResult; }
private function _sGenToken($iUid, $sScope) { $tokenApi = $this->_aConf['tokenApi']; $oOption = new Ko_Tool_SQL(); $tokenInfo = $this->{$tokenApi}->aGetList($oOption->oWhere('uid = ? and cid = ?', $iUid, $this->_sClientId)->oLimit(1)); if (!empty($tokenInfo)) { $aUpdate = array('scope' => $sScope, 'ctime' => date('Y-m-d H:i:s')); $this->{$tokenApi}->iUpdate($tokenInfo[0], $aUpdate); return $tokenInfo[0]['token']; } $token = Ko_Tool_OAuth::SGenKey(); $aData = array('cid' => $this->_sClientId, 'token' => $token, 'uid' => $iUid, 'scope' => $sScope, 'ctime' => date('Y-m-d H:i:s')); $this->{$tokenApi}->aInsert($aData); return $token; }
public function _vSyncAll_Callback($aInfo, $iNo) { $dbDao = $this->_aConf['db'] . 'Dao'; $mcDao = $this->_aConf['mc'] . 'Dao'; $key = $this->_sGetMCKey($aInfo); $mcinfo = intval($this->{$mcDao}->vGet($key)); if ($mcinfo) { $update = array('mtime' => date('Y-m-d H:i:s')); $change = array('times' => $mcinfo); $oOption = new Ko_Tool_SQL(); $oOption->oWhere('mtime = ?', $aInfo['mtime']); if ($this->{$dbDao}->iUpdate($aInfo, $update, $change, $oOption)) { $this->{$mcDao}->iDecrement($key, $mcinfo); } } }
private function _bUpdatePersistentToken($iUid, $sSeries, $sToken, &$sNewToken) { if ($this->_iGetPersistentStrict()) { // 每个 persistent_token 只能验证一次,如果重复验证可能是因为数据被重复提交,或者失窃 $sNewToken = $this->_sGetNewSalt(); $sMtime = date('Y-m-d H:i:s'); $aUpdate = array('token' => $sNewToken, 'mtime' => $sMtime); $persistentDao = $this->_aConf['persistent'] . 'Dao'; $key = array('uid' => $iUid, 'series' => $sSeries); $oOption = new Ko_Tool_SQL(); $oOption->oWhere('token = ?', $sToken); return $this->{$persistentDao}->iUpdate($key, $aUpdate, array(), $oOption) ? true : false; } else { // 每次不更新 token,只做延期 $sNewToken = $sToken; $sMtime = date('Y-m-d H:i:s'); $aUpdate = array('mtime' => $sMtime); $persistentDao = $this->_aConf['persistent'] . 'Dao'; $key = array('uid' => $iUid, 'series' => $sSeries); $oOption = new Ko_Tool_SQL(); $oOption->oWhere('token = ?', $sToken); $this->{$persistentDao}->iUpdate($key, $aUpdate, array(), $oOption); return true; } }
private function _aGetChildList($aId) { $ret = array(); if (!empty($aId)) { $treeApi = $this->_aConf['treeApi']; $option = new Ko_Tool_SQL(); $list = $this->{$treeApi}->aGetList($option->oWhere('pid in (?)', $aId)->oForceMaster(true)); foreach ($list as $v) { $ret[$v['pid']][$v['id']] = array(); } } return $ret; }
private function _aGetReplyCids($iOid, $aIndexCid) { if (empty($aIndexCid)) { return array(); } $replyDao = $this->_aConf['reply'] . 'Dao'; $oOption = new Ko_Tool_SQL(); $oOption->oWhere('thread_cid in (?)', $aIndexCid)->oOrderBy('cid desc')->oLimit(self::MAX_REPLY); $aReply = $this->{$replyDao}->aGetList($iOid, $oOption); return Ko_Tool_Utils::AObjs2ids($aReply, 'cid'); }
/** * 用户查看会话消息列表详情,根据最小id查询 * * @return array */ public function aGetMessageListByMinmid($iUid, $iThread, $iMinmid, $iNum, $bAutoRead = true) { if (isset($this->_aConf['userthread'])) { $userthreadDao = $this->_aConf['userthread'] . 'Dao'; $info = $this->{$userthreadDao}->aGet(array('uid' => $iUid, 'mid' => $iThread)); if (empty($info)) { return array(); } if ($bAutoRead && $info['unread']) { $this->{$userthreadDao}->iUpdate(array('uid' => $iUid, 'mid' => $iThread), array('unread' => 0)); } } $oOption = new Ko_Tool_SQL(); if (isset($this->_aConf['userthread'])) { $oOption->oWhere('ctime >= ?', $info['jointime']); } $oOption->oAnd('mid > ?', $iMinmid)->oOrderBy('mid desc')->oLimit($iNum); return $this->_aGetMessageList($iUid, $iThread, $oOption); }
/** * 直接获取用户的授权信息 * * @return array 返回用户授权信息 array(token, secret) */ public function aGetUserTokenDirect($iCid, $iUid, $sScope = '') { $tokenApi = $this->_aConf['tokenApi']; $oOption = new Ko_Tool_SQL(); $tokenInfo = $this->{$tokenApi}->aGetList($oOption->oWhere('uid = ? and cid = ?', $iUid, $iCid)->oLimit(1)); if (!empty($tokenInfo)) { $aUpdate = array('scope' => $sScope, 'ctime' => date('Y-m-d H:i:s')); $this->{$tokenApi}->iUpdate($tokenInfo[0], $aUpdate); return array($tokenInfo[0]['token'], $tokenInfo[0]['secret']); } $sToken = Ko_Tool_OAuth::SGenKey(); $sSecret = Ko_Tool_OAuth::SGenKey(); $aData = array('cid' => $iCid, 'token' => $sToken, 'secret' => $sSecret, 'uid' => $iUid, 'scope' => $sScope, 'ctime' => date('Y-m-d H:i:s')); $this->{$tokenApi}->aInsert($aData); return array($sToken, $sSecret); }
private function _bUpdate($vObj, $sAction, $iMaxTimes, $iTimes) { $change = array('times' => $iTimes); $oOption = new Ko_Tool_SQL(); $oOption->oWhere('times <= ?', $iMaxTimes - $iTimes); if ($this->_iUpdate($vObj, $sAction, array(), $change, $oOption)) { return true; } return false; }
private function _vInsertIpRoles($sIp, $aConfig, $aUnknown) { foreach ($aConfig as $service => &$v) { foreach ($v as $pid => &$vv) { ksort($vv); foreach ($vv as $pname => &$vvv) { sort($vvv); } unset($vvv); } unset($vv); } unset($v); foreach ($aConfig as $service => $v) { usort($v, array($this, '_iComIpRoles')); $config = array(); foreach ($v as $pid => $vv) { foreach ($vv as $pname => $vvv) { $config[$pid][] = array('pname' => $pname, 'localaddr' => implode(' ', $vvv)); } } $this->_aInsertIpRole($sIp, $service, $config); echo date('Y-m-d H:i:s'), "\t", long2ip($sIp), "\t", $service, "\n"; } $newroles = array_keys($aConfig); if (!empty($aUnknown)) { $newroles[] = 'unknown'; $this->_aInsertIpRole($sIp, 'unknown', $aUnknown); } $iproleApi = $this->_aConf['iproleApi']; $option = new Ko_Tool_SQL(); $this->{$iproleApi}->iDeleteByCond($option->oWhere('ip = ? and role not in (?)', $sIp, $newroles)); }
public function deleteAlbum($uid, $albumid) { if (!$uid) { return false; } $recycleid = $this->_getRecycleAlbumid($uid); if ($albumid == $recycleid) { return false; } $albumkey = compact('uid', 'albumid'); $album = $this->albumDao->aGet($albumkey); if (empty($album)) { return false; } $option = new Ko_Tool_SQL(); $pcount = $this->photoDao->iUpdateByCond($option->oWhere('albumid = ?', $albumid), array('albumid' => $recycleid, 'sort' => time())); $this->albumDao->iDelete($albumkey); $recyclekey = array('uid' => $uid, 'albumid' => $recycleid); $this->albumDao->iUpdate($recyclekey, array(), array('pcount' => $pcount)); return true; }
private function _vSubTags($uid, $blogid, $tags) { foreach ($tags as $tag) { $taglistkey = compact('uid', 'tag', 'blogid'); if ($this->taglistDao->iDelete($taglistkey)) { $taginfokey = compact('uid', 'tag'); $option = new Ko_Tool_SQL(); $this->taginfoDao->iUpdate($taginfokey, array(), array('bcount' => -1), $option->oWhere('bcount > ?', 0)); } } }
public function vDeleteByKind($uid, $kind) { $msgtypes = $this->_aKind2MsgTypes($kind); $userDao = $this->_aConf['user'] . 'Dao'; $option = new Ko_Tool_SQL(); $option->oWhere('msgtype in (?)', $msgtypes); $splitField = $this->{$userDao}->sGetSplitField(); if (strlen($splitField)) { $this->{$userDao}->iDeleteByCond($uid, $option); } else { $option->oAnd('uid = ?', $uid); $this->{$userDao}->iDeleteByCond($option); } }