process(); $this->loginSuccess = true; $this->loginMsg = 'success'; } catch (Throwable $throwable) { $this->loginSuccess = false; $this->loginMsg = $throwable->getMessage(); throw $throwable; } finally { $this->writeLoginLog(); } // 返回 return $res; } /** * @return void */ private function writeLoginLog(): void { $userInfo = $this->adminUserRepository->findByUserName($this->request->input('username')); $context = [ 'username' => $this->request->input('username',''), 'password' => $this->request->input('password',''), 'user_info' => $userInfo?->toArray() ?? [], 'ip' => $this->getClientIp(), 'os' => $this->getClientOs(), 'browser' => $this->request->header('User-Agent') ?: 'unknown', ]; Coroutine::create(function () use ($userInfo, $context) { $this->logger->request()->info('admin_login_log', $context); $this->adminUserLoginLogModel->create([ 'admin_user_id' => $userInfo?->id ?? 0, 'username' => $userInfo?->username ?? '', 'ip' => current($context['ip']) ?: '0.0.0.0', 'os' => $context['os'], 'browser' => $context['browser'] ?? '', 'status' => $this->loginSuccess ? 1 : 2, 'message' => $this->loginMsg, ]); }); } }