Esempio n. 1
0
 public function createAction()
 {
     MyTool::simpleView($this);
     if (!MyTool::loginAuth($this)) {
         return MyTool::onExit($this, MyConst::STATUS_NOT_LOGIN, 'must login first');
     }
     $body = $this->request->getJsonRawBody();
     if (empty($body)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'mal-json input data');
     }
     $team = TeamLogic::convertJsonToTeam($body);
     if (empty($team)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'invalid input');
     }
     $uid = @intval(MyTool::getCookie($this, MyConst::COOKIE_UID));
     $team->owner = $uid;
     try {
         if (false === $team->save()) {
             return MyTool::onExit($this, MyConst::STATUS_ERROR, "create team failed");
         }
     } catch (Exception $e) {
         return MyTool::onExit($this, MyConst::STATUS_ERROR, $e->getMessage());
     }
     MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK);
     return true;
 }