diff --git a/webapp/bootstrap/init.php b/webapp/bootstrap/init.php index e52a7ed..fd33c6e 100644 --- a/webapp/bootstrap/init.php +++ b/webapp/bootstrap/init.php @@ -40,6 +40,11 @@ function emptyReplace($val, $defVal) return !empty($val) ? $val :$defVal; } +function isValidSex($sex) +{ + return in_array($sex, array(0, 1, 2)); +} + $_myself = null; function myself() diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index 19f7c7b..fea525b 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -11,6 +11,7 @@ require_once('mt/Rank.php'); require_once('services/PropertyChgService.php'); require_once('services/SeasonService.php'); +require_once('services/NameService.php'); use phpcommon\SqlHelper; use models\User; @@ -102,6 +103,49 @@ class UserController extends BaseAuthedController { $sex = getReqVal('sex', 0); $headId = getReqVal('head_id', 0); $headFrame = getReqVal('head_frame', 0); + + $userInfo = $this->_getOrmUserInfo(); + if ($userInfo['activated']) { + $this->_rspErr(10, '不能重复激活'); + return; + } + $nameService = new services\NameService(); + if (!$nameService->verifyNameSign($param1, $param2)){ + $this->_rspErr(1, '参数错误名,签名校验失败'); + return; + } + if (!$nameService->nameUsed($param1)){ + $this->_rspErr(2, '名字已被占用'); + return; + } + if (!isValidSex($sex)) { + $this->_rspErr(1, '参数错误名,sex不合法'); + return; + } + if (User::isValidHeadId($userInfo, $headId)) { + $this->_rspErr(1, '参数错误名,head_id不合法'); + return; + } + if (User::isValidHeadFrame($userInfo, $headFrame)) { + $this->_rspErr(1, '参数错误名,head_frame不合法'); + return; + } + if (!$nameService->useName($name)) { + $this->_rspErr(2, '名字已被占用'); + return; + } + $this->_updateUserInfo(array( + 'name' => $name, + 'sex' => $sex, + 'head_id' => $headId, + 'head_frame' => $headFrame, + 'activated' => 1 + )); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addUserChg(); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto() + )); } public function update() diff --git a/webapp/models/User.php b/webapp/models/User.php index 3fa1275..7965f5f 100644 --- a/webapp/models/User.php +++ b/webapp/models/User.php @@ -21,8 +21,8 @@ class User extends BaseModel { 'diamond' => $row['diamond'], 'hero_id' => $row['hero_id'], 'first_fight' => $row['first_fight'], - 'head_list' => !empty($row['head_list']) ? json_decode($row['head_list'], true) : array(), - 'head_frame_list' => !empty($row['head_frame_list']) ? json_decode($row['head_frame_list'], true) : array(), + 'head_list' => self::getHeadList($row), + 'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()), ); } @@ -43,9 +43,30 @@ class User extends BaseModel { 'diamond' => $row['diamond'], 'hero_id' => $row['hero_id'], 'first_fight' => $row['first_fight'], - 'head_list' => !empty($row['head_list']) ? json_decode($row['head_list'], true) : array(), - 'head_frame_list' => !empty($row['head_frame_list']) ? json_decode($row['head_frame_list'], true) : array(), + 'head_list' => self::getHeadList($row), + 'head_frame_list' => emptyReplace(json_decode($row['head_frame_list'], true), array()), ); } + public static function isValidHeadId($userInfo, $headId) + { + $headList = self::getHeadList($userInfo); + return in_array($headId, $headList); + } + + public static function isValidHeadFrame($userInfo, $headFrame) + { + $headFrameList = !empty($userInfo['head_frame_list']) ? + json_decode($userInfo['head_frame_list'], true) : array(); + return in_array($headFrame, $headFrameList); + } + + private static function getHeadList($userInfo) + { + $headList = !empty($userInfo['head_list']) ? json_decode($userInfo['head_list'], true) : array(); + $heroList = array(); + $heroSkinList = array(); + return $headList; + } + }