request->isPost()) { return JsonService::fail('请使用POST请求'); } $params = $this->request->post(); if (array_diff(array_keys($params), ['account', 'password']) !== [] || !is_string($params['account'] ?? null) || $params['account'] === '' || strlen($params['account']) > 4096 || str_contains($params['account'], "\0") || !is_string($params['password'] ?? null) || $params['password'] === '' || strlen($params['password']) > 4096 || str_contains($params['password'], "\0")) { return JsonService::fail('登录参数不合法'); } $params = (new LoginValidate())->post()->goCheck('verify'); return $this->data(IdentitySessionService::verify($params)); } public function login() { if (!$this->request->isPost()) { return JsonService::fail('请使用POST请求'); } // 沿用原限流与字段校验,服务仍须在账号锁内重验当前凭据。 $params = (new LoginValidate())->post()->goCheck(); return $this->data(IdentitySessionService::login($params)); } public function password() { if (!$this->request->isPost()) { return JsonService::fail('请使用POST请求'); } IdentitySessionService::changePassword((string) $this->request->header('token', ''), $this->request->post()); return $this->success('密码修改成功,请重新登录'); } public function logout() { if (!$this->request->isPost()) { return JsonService::fail('请使用POST请求'); } $params = $this->request->post(); if (array_diff(array_keys($params), ['all']) !== [] || !in_array($params['all'] ?? 0, [0, 1, '0', '1'], true)) { return JsonService::fail('退出参数不合法'); } IdentitySessionService::logout((string) $this->request->header('token', ''), (int) ($params['all'] ?? 0) === 1); return $this->success('已退出登录'); } }