/** * cgi/login/{user}/{password} */ public function indexAction() { $account = @trim(MyTool::get($this, MyConst::PARAM_USER_ACCOUNT)); $password = @trim(MyTool::get($this, MyConst::PARAM_USER_PASSWORD)); if (!$this->checkParams($account, $password)) { return $this->onError(MyConst::STATUS_INVALID_PARAM, 'need account and password'); } $user = $this->getUserInfo($account); if (empty($user)) { return $this->onError(MyConst::STATUS_INVALID_USER, 'unknown user id'); } if (!$this->checkPassword($user, $password)) { return $this->onError(MyConst::STATUS_INVALID_PASSWORD, 'invalid password'); } MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK); MyTool::setVar($this, MyConst::FIELD_USER, $user); $ts = time(); if (!MyTool::hasCookie($this, MyConst::COOKIE_UUID)) { MyTool::setCookie($this, MyConst::COOKIE_UUID, MyTool::genUuid($ts), MyConst::COOKIE_NEVER_EXPIRE); } MyTool::setCookie($this, MyConst::COOKIE_TOKEN, MyTool::genToken($this, $user->id, $ts), MyConst::COOKIE_EXPIRE); MyTool::setCookie($this, MyConst::COOKIE_UID, $user->id, MyConst::COOKIE_EXPIRE); MyTool::setCookie($this, MyConst::COOKIE_TS, $ts, MyConst::COOKIE_EXPIRE); return true; }