Exemple #1
0
 public function errorAction($exception)
 {
     $ini = \Sooh\Base\Ini::getInstance();
     $render = $ini->viewRenderType();
     switch ($render) {
         case "json":
             header('Content-type: application/json');
             break;
         case 'jsonp':
             break;
         default:
             $ini->viewRenderType('json');
             header('Content-type: application/json');
             break;
     }
     if (is_a($exception, '\\Sooh\\DB\\Acl\\ErrNeedsLogin')) {
         \Sooh\Base\Log\Data::getInstance()->ret = 'needs login';
         //		}elseif(is_a($exception,'\Prj\ErrCode')){
         //			$this->_view->assign('code',$exception->getCode());
         //			$this->_view->assign('msg',$exception->getMessage());
         //			\Sooh\Base\Log\Data::getInstance()->ret = $exception->getMessage();
         //		}elseif(is_a($exception,'\Prj\RetCode')){
         //			$this->_view->assign('code',200);
         //			$this->_view->assign('msg',$exception->getMessage());
     } else {
         var_log($exception);
         $this->_view->assign('code', $exception->getCode());
         $this->_view->assign('msg', $exception->getMessage());
         \Sooh\Base\Log\Data::getInstance()->ret = $exception->getMessage();
     }
 }
Exemple #2
0
 protected function onInit_chkLogin()
 {
     $userIdentifier = \Sooh\Base\Session\Data::getInstance()->get('accountId');
     if ($userIdentifier) {
         \Sooh\Base\Log\Data::getInstance()->userId = $userIdentifier;
         $this->user = \Prj\Data\User::getCopy($userIdentifier);
     } else {
         throw new \ErrorException(\Prj\ErrCode::errNotLogin, 401);
     }
 }
Exemple #3
0
 /**
  * 记录打开页面的情况
  * 
  * @input string page 页面名(标示)
  * @input string httpReferer httpReferer
  * @sample {api_uri}&page=intro.html&httpReferer=www.baidu.com
  * @return {"code":200,"msg":""} 正常情况
  */
 public function openpageAction()
 {
     $loger = \Sooh\Base\Log\Data::getInstance();
     $loger->evt = 'openpage';
     $loger->target = $this->_request->get('page');
     $loger->userId = \Sooh\Base\Session\Data::getInstance()->get('accountId');
     $loger->ext = $this->_request->get('httpReferer');
     $this->_view->assign('code', '200');
     $this->_view->assign('msg', '');
 }
Exemple #4
0
 public function loginAction()
 {
     $acc = $this->getAccount();
     try {
         $validImg = $this->_request->get('valid');
         $sessionData = \Sooh\Base\Session\Data::getInstance();
         error_log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>{$validImg} !=" . $sessionData->get('validImg'));
         if ($validImg !== $sessionData->get('validImg')) {
             return $this->returnError('invalidCode');
         }
         $accountInfo = $acc->login($this->_request->get('loginname'), $this->_request->get('passwd'), 'local', array('contractId', 'rights'));
         $this->onLogin($accountInfo);
         \Sooh\Base\Log\Data::getInstance()->ret = 'login ok';
     } catch (\Exception $e) {
         \Sooh\Base\Log\Data::getInstance()->ret = $e->getMessage();
         $this->returnError($e->getMessage(), $e->getCode());
     }
 }
Exemple #5
0
 public function init()
 {
     $this->ini = \Sooh\Base\Ini::getInstance();
     if ($this->_request->isPost()) {
         $this->onInit_chkMaintainTime();
     }
     list($deviceId, $uid) = $this->initSession();
     \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\TextAll(), 'trace');
     \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\TextAll(), 'error');
     \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\Database('dbgrpForLog', 2), 'evt');
     $log = \Sooh\Base\Log\Data::getInstance('c');
     $log->clientType = 0;
     $log->deviceId = $deviceId;
     $log->contractId = '0';
     $log->evt = $this->_request->getModuleName() . '/' . $this->_request->getControllerName() . '/' . $this->_request->getActionName();
     $log->isLogined = 0;
     $log->userId = $uid;
 }
Exemple #6
0
 public function indexAction()
 {
     if ($this->_request->get('dowhat') == 'logout') {
         $this->_view->assign('useTpl', 'logout');
         \Sooh\Base\Session\Data::getInstance()->set('managerId', '');
     } elseif ($this->manager) {
         //已经登入,进主页
         $this->manager->load();
         $this->_view->assign('leftmenus', $this->manager->acl->getMenuMine());
         $this->_view->assign('useTpl', 'homepage');
     } else {
         //尚未登入,去登入页
         $u = $this->_request->get('u');
         $p = $this->_request->get('p');
         if (!empty($u) && !empty($p)) {
             $this->ini->viewRenderType('json');
             $acc = \Lib\Services\Manager::getInstance(null);
             try {
                 $validImg = $this->_request->get('valid');
                 $sessionData = \Sooh\Base\Session\Data::getInstance();
                 if ($validImg !== $sessionData->get('validImg')) {
                     return $this->returnError('invalidCode');
                 }
                 $accountInfo = $acc->login($u, $p, 'local', array('rights'));
                 $log = \Sooh\Base\Log\Data::getInstance();
                 $log->ret = 'login ok';
                 $log->ext = $accountInfo['nickname'];
                 $sessionData->set('managerId', $accountInfo['accountId']);
                 $sessionData->set('nickname', $accountInfo['nickname']);
                 $this->returnOK();
             } catch (\Exception $e) {
                 \Sooh\Base\Log\Data::getInstance()->ret = $e->getMessage();
                 $this->returnError($e->getMessage());
             }
         } else {
             $acc = \Lib\Services\Manager::getInstance(null);
             $acc->addFirstAccount();
             $this->_view->assign('useTpl', 'login');
         }
     }
 }
Exemple #7
0
 /**
  * 预发放道具
  * @param array $bonusThisTime
  * @param string $accountId
  * @param \Lib\Items\Interfaces $_ignore_
  * @return type
  */
 public static function batchGive_pre($bonusThisTime, $accountId, $_ignore_ = null)
 {
     $givedThisTime = array();
     foreach ($bonusThisTime as $itemname => $num) {
         $_ignore_ = self::create($itemname, $accountId);
         try {
             $_ignore_->giveToUser_prepare($num, $accountId, '签到奖励');
             $givedThisTime[] = $_ignore_;
         } catch (\ErrorException $ex) {
             error_log("give bonus {$itemname} to {$accountId} failed as " . $ex->getMessage() . "\n" . $ex->getTraceAsString());
             $_ignore_->giveToUser_rollback('trans_rollback');
             break;
         }
     }
     $remain = $_ignore_->remain();
     if (is_array($remain)) {
         $remain = sizeof($remain);
     }
     \Sooh\Base\Log\Data::getInstance()->setThese('', '', $itemname, $num, $remain);
     return $givedThisTime;
 }
Exemple #8
0
 protected function error($msg, $code = 400)
 {
     \Sooh\Base\Log\Data::getInstance()->ret = $msg;
     $this->_view->assign('code', $code);
     $this->_view->assign('msg', $msg);
 }
Exemple #9
0
 protected function onInit_chkLogin()
 {
     $this->session = \Sooh\Base\Session\Data::getInstance();
     if ($this->session) {
         $userId = $this->session->get('managerId');
         if ($userId) {
             \Sooh\Base\Log\Data::getInstance()->userId = $userId;
             $this->manager = \Prj\Data\Manager::getCopyByManagerId($userId);
             $this->manager->load();
             if (!$this->manager->acl->hasRightsFor($this->_request->getModuleName(), $this->_request->getControllerName())) {
                 $this->returnError(\Prj\ErrCode::errNoRights, 300);
             }
         } else {
             $this->returnError(\Prj\ErrCode::errNotLogin, 301);
         }
     }
 }
Exemple #10
0
 /**
  * 签到
  * @param boolean $withBonus 返回里是否带奖励物品列表
  * @param \Prj\Data\User $userOrAccountId accountId 或 \Prj\Data\User
  * @return array
  */
 public function doCheckIn($withBonus, $userOrAccountId)
 {
     if ($this->rpc !== null) {
         return $this->rpc->initArgs(array('withBonus' => $withBonus, 'userOrAccountId' => $userOrAccountId))->send(__FUNCTION__);
     } else {
         if (is_scalar($userOrAccountId)) {
             $userOrAccountId = \Prj\Data\User::getCopy($userOrAccountId);
         }
         $userOrAccountId->load();
         if ($userOrAccountId->exists() === false) {
             $userOrAccountId->setField(self::fieldUser, array());
             $userOrAccountId->update();
         }
         $this->decode($userOrAccountId->getField(self::fieldUser, true));
         if ($this->r['ymd'] == $this->today) {
             \Sooh\Base\Log\Data::getInstance()->ret = "checkin already";
             return $this->errFound(self::errTodayDone, 400, $withBonus);
         } elseif (sizeof($this->r['checked']) >= self::maxMonth) {
             \Sooh\Base\Log\Data::getInstance()->ret = 'checkin of this month:all done';
             return $this->errFound(self::errMonthDone, 400, $withBonus);
         }
         $accountId = $userOrAccountId->getAccountId();
         $idCheckThisTime = array_sum($this->r['checked']);
         $bonusThisTime = $this->getBonusList()[$idCheckThisTime];
         if (false === $userOrAccountId->lock('chkinBonus:' . http_build_query($bonusThisTime))) {
             \Sooh\Base\Log\Data::getInstance()->ret = "lock user for checkin failed";
             \Prj\Loger::alarm('[LockFailed] user-table on checkin' . \Sooh\DB\Broker::lastCmd());
             return $this->errFound(\Sooh\Base\ErrException::msgServerBusy, 500, $withBonus);
         }
         //\Lib\Items\Broker::iniForGiven('Voucher', array('iniDefaultForGive_a'=>60));// 如果有道具发放时有额外参数要设置(比如有效期不同)
         $givedThisTime = \Lib\Items\Broker::batchGive_pre($bonusThisTime, $accountId);
         if (sizeof($givedThisTime) == sizeof($bonusThisTime)) {
             if (\Lib\Items\Broker::batchGive_confirm($givedThisTime, $accountId)) {
                 try {
                     $this->r['checked'][$idCheckThisTime] = 1;
                     $this->r['bonusGot'][$idCheckThisTime] = $bonusThisTime;
                     $this->r['ymd'] = $this->today;
                     $userOrAccountId->setField(self::fieldUser, $this->r);
                     $userOrAccountId->update();
                     \Sooh\Base\Log\Data::getInstance()->ret = "done";
                     return $this->allDone(self::msgCheckinDone, $withBonus);
                 } catch (\ErrorException $errOnUpdate) {
                     \Prj\Loger::alarm('[CheckInFailed] on update user:'******'[GiveItemFailed] on checkin');
             \Sooh\Base\Log\Data::getInstance()->ret = "give item failed";
         } else {
             \Sooh\Base\Log\Data::getInstance()->ret = "update user failed";
         }
         if (\Lib\Items\Broker::batchGive_rollback('GiveItemFailedOnCheckin', $givedThisTime, $accountId)) {
             $userOrAccountId->unlock();
             return $this->errFound(\Sooh\Base\ErrException::msgServerBusy, 500, $withBonus);
         } else {
             return $this->errFound(\Sooh\Base\ErrException::msgServerBusy, 500, $withBonus);
         }
     }
 }