Ejemplo n.º 1
0
 public function setAction($field)
 {
     MyTool::simpleView($this);
     $field = @trim($field);
     if (!array_key_exists($field, self::$FIELDS)) {
         return $this->onError(MyConst::STATUS_INVALID_PARAM, 'invalid param');
     }
     if (!MyTool::loginAuth($this)) {
         return $this->onError(MyConst::STATUS_NOT_LOGIN, 'must login first');
     }
     $uid = MyTool::getCookie($this, MyConst::COOKIE_UID);
     $user = $this->getUserInfo($uid);
     if (empty($user)) {
         return $this->onError(MyConst::STATUS_INVALID_USER, 'unknown user id');
     }
     $value = MyTool::get($this, MyConst::FIELD_VALUE);
     if (MyTool::eq($field, MyConst::FIELD_OPEN)) {
         $value = MyTool::eq($value, '1') ? 1 : 0;
     }
     $value2 = null;
     if (MyTool::eq($user->{$field}, $value)) {
         return $this->onError(MyConst::STATUS_OK, 'nothing changed');
     }
     if (MyTool::eq($field, MyConst::FIELD_PASSWORD)) {
         if (!MyTool::isPassword($value)) {
             return $this->onError(MyConst::STATUS_INVALID_PASSWORD, 'invalid password');
         }
         $value2 = MyTool::get($this, MyConst::FIELD_VALUE2);
         if (0 !== strcasecmp($user->{$field}, $value2)) {
             return $this->onError(MyConst::STATUS_WRONG_PASSWORD, 'current password wrong');
         }
     } else {
         if (MyTool::eq($field, MyConst::FIELD_EMAIL)) {
             if (!MyTool::isEmail($value)) {
                 return $this->onError(MyConst::STATUS_INVALID_EMAIL, 'wrong email address');
             }
         } else {
             if (MyTool::eq($field, MyConst::FIELD_PHONE)) {
                 if (!MyTool::isPhone($value)) {
                     return $this->onError(MyConst::STATUS_INVALID_PHONE, 'wrong phone number');
                 }
             }
         }
     }
     $user->{$field} = $value;
     $user->mtime = MyTool::now();
     if (true !== $user->update()) {
         return $this->onError(MyConst::STATUS_DB, 'update user information failed');
     }
     MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK);
     return true;
 }
Ejemplo n.º 2
0
 public function updateLeaderAction($teamId, $leaderId)
 {
     MyTool::simpleView($this);
     if (!MyTool::loginAuth($this)) {
         return $this->onError(MyConst::STATUS_NOT_LOGIN, 'must login first');
     }
     $teamId = @intval($teamId);
     $team = TeamLogic::getTeam($teamId);
     if (empty($team)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_TEAM, 'unknown team id');
     }
     $uid = MyTool::getCookie($this, MyConst::COOKIE_UID);
     if ($team->owner != $uid) {
         return MyTool::onExit($this, MyConst::STATUS_NO_PERMISSION, 'no premission');
     }
     if (empty($leader)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'invalid input');
     }
     $leader = TeamLogic::getLeader($id);
     if (empty($leader)) {
         return MyTool::onExit($this, MyConst::STATUS_UNKNOWN_LEADER, 'unknown leader');
     }
     if ($leader->tid != $teamId) {
         return MyTool::onExit($this, MyConst::STATUS_NO_PERMISSION, 'no permission');
     }
     $body = $this->request->getJsonRawBody();
     if (empty($body)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'mal-json input data');
     }
     $leader2 = TeamLogic::convertJsonToLeader($body);
     if (empty($leader2)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'invalid input');
     }
     if (MyTool::eq($leader->name, $leader2->name)) {
         $leader->name = $leader2->name;
     }
     if (MyTool::eq($leader->pic, $leader2->pic)) {
         $leader->pic = $leader2->pic;
     }
     if (MyTool::eq($leader->role, $leader2->role)) {
         $leader->role = $leader2->role;
     }
     if (MyTool::eq($leader->intro, $leader2->intro)) {
         $leader->intro = $leader2->intro;
     }
     $leader->mtime = $leader2->ctime;
     try {
         if (true !== $leader->update()) {
             return MyTool::onExit($this, MyConst::STATUS_ERROR, "update team leader failed");
         }
     } catch (Exception $e) {
         return MyTool::onExit($this, MyConst::STATUS_ERROR, $e->getMessage());
     }
     MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK);
     return true;
 }