/** * cgi/singup */ public function indexAction() { $body = $this->request->getJsonRawBody(); if (empty($body)) { return $this->onExit(MyConst::STATUS_INVALID_PARAM, 'mal-json input data'); } $user = SignupLogic::convert($body); if (empty($user)) { return $this->onExit(MyConst::STATUS_INVALID_PARAM, 'missing some required field'); } if (!MyTool::isEmail($user->email)) { return $this->onExit(MyConst::STATUS_INVALID_EMAIL, 'bad email input'); } if (!MyTool::isPhone($user->phone)) { return $this->onExit(MyConst::STATUS_INVALID_EMAIL, 'bad phone input'); } if (!MyTool::isPassword($user->password)) { return $this->onExit(MyConst::STATUS_INVALID_EMAIL, 'bad password input'); } try { if (false === SignupLogic::create($user)) { return $this->onExit(MyConst::STATUS_ERROR, 'system error'); } } catch (Exception $e) { return $this->onExit(MyConst::STATUS_ERROR, $e->getMessage()); } MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK); MyTool::setVar($this, 'user', $user); return true; }
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; }