feat: 号池操作列可以重新登录这个账号

This commit is contained in:
2026-11-10 09:08:31 +08:00
parent e3d7a05e0e
commit 339b169f3c
4 changed files with 40 additions and 9 deletions
+11
View File
@@ -163,6 +163,9 @@ async def nqi_start(body: dict) -> dict:
await purge()
username = str(body.get("username") or "").strip()
purpose = "pool" if body.get("purpose") == "pool" else "login"
lock_account = purpose == "pool" and bool(body.get("lockAccount"))
if lock_account and not username:
raise _bad("请选择要重新登录的账号")
resume_cookies: list = []
resume_name = username
with session_scope() as session:
@@ -191,6 +194,8 @@ async def nqi_start(body: dict) -> dict:
client = NqiClient()
try:
challenge = await client.open_login()
if lock_account:
challenge.expected_login = username
except NqiError as exc:
await client.aclose()
raise _bad(str(exc)) from exc
@@ -244,6 +249,8 @@ async def nqi_finish(body: dict) -> dict:
sms_code = str(body.get("smsCode") or "").strip()
if not username or not password or not captcha:
raise _bad("请填写账号、密码和验证码")
if challenge.expected_login and username != challenge.expected_login:
raise _bad("请使用原来的账号重新登录")
try:
if not challenge.config_ready:
code = await client.prepare_login(challenge, username, password, captcha)
@@ -260,6 +267,10 @@ async def nqi_finish(body: dict) -> dict:
pass
return {**_captcha_body(session_id, challenge), "status": "need_captcha", "message": message}
challenge.password = ""
if challenge.expected_login and str(user.get("loginId") or "").strip() != challenge.expected_login:
await client.aclose()
drop(session_id)
raise _bad("登录的不是这个账号")
adhoc_ready = await client.renew_ticket()
cookies = client.export_cookies()
await client.aclose()
+1
View File
@@ -99,6 +99,7 @@ class LoginChallenge:
password: str = ""
captcha: str = ""
config_ready: bool = False
expected_login: str = ""
@dataclass
+23 -4
View File
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { NButton, NIcon, NInput, NModal, NTooltip, useDialog } from "naive-ui";
import { CheckmarkCircleOutline, TrashOutline } from "@vicons/ionicons5";
import { CheckmarkCircleOutline, LogInOutline, TrashOutline } from "@vicons/ionicons5";
import Shell from "../../shell/Shell.vue";
import LoginView from "../auth/LoginView.vue";
import { api } from "../../shared/http";
@@ -19,6 +19,7 @@ interface Account {
const accounts = ref<Account[]>([]);
const keyword = ref("");
const show = ref(false);
const relogin = ref("");
const checkingAll = ref(false);
const checkingId = ref<number | null>(null);
const dialog = useDialog();
@@ -87,6 +88,16 @@ async function remove(id: number) {
}
}
function openAdd() {
relogin.value = "";
show.value = true;
}
function openRelogin(account: Account) {
relogin.value = account.loginId;
show.value = true;
}
function confirmRemove(account: Account) {
dialog.warning({
title: "删除账号",
@@ -109,7 +120,7 @@ onMounted(load);
<div class="page-head-actions">
<n-input v-model:value="keyword" clearable placeholder="搜索账号、姓名或地市" />
<n-button :loading="checkingAll" @click="checkAll">检查</n-button>
<n-button type="primary" @click="show = true">添加账号</n-button>
<n-button type="primary" @click="openAdd">添加账号</n-button>
</div>
</header>
<div class="admin-scroll">
@@ -144,6 +155,14 @@ onMounted(load);
</template>
检查
</n-tooltip>
<n-tooltip>
<template #trigger>
<n-button size="small" quaternary circle aria-label="重新登录" @click="openRelogin(account)">
<template #icon><n-icon :component="LogInOutline" /></template>
</n-button>
</template>
重新登录
</n-tooltip>
<n-tooltip>
<template #trigger>
<n-button size="small" quaternary circle aria-label="删除" @click="confirmRemove(account)">
@@ -163,8 +182,8 @@ onMounted(load);
</div>
</div>
</section>
<n-modal v-model:show="show" class="app-dialog" preset="card" title="添加账号">
<LoginView purpose="pool" @done="show = false; load()" />
<n-modal v-model:show="show" class="app-dialog" preset="card" :title="relogin ? '重新登录' : '添加账号'">
<LoginView :key="relogin || 'new'" purpose="pool" :account="relogin || undefined" @done="show = false; load()" />
</n-modal>
</Shell>
</template>
+5 -5
View File
@@ -8,13 +8,13 @@ import ThemeButton from "../../shell/ThemeButton.vue";
import "./login-gate.css";
const BROKEN_CAPTCHA = "data:,";
const props = defineProps<{ purpose?: "login" | "pool" }>();
const props = defineProps<{ purpose?: "login" | "pool"; account?: string }>();
const emit = defineEmits<{ done: [] }>();
const route = useRoute();
const router = useRouter();
const toast = useToast();
const mode = ref("local");
const username = ref("");
const username = ref(props.account || "");
const password = ref("");
const captcha = ref("");
const captchaUrl = ref("");
@@ -189,7 +189,7 @@ async function startNqi() {
try {
const result = await api<{ status: string; token?: string; user?: { role: string; name: string }; sessionId?: string; captcha?: string }>("/api/auth/nqi/start", {
method: "POST",
body: JSON.stringify({ username: username.value, purpose: props.purpose || "login" }),
body: JSON.stringify({ username: username.value, purpose: props.purpose || "login", lockAccount: Boolean(props.account) }),
});
if (result.status === "ok" && result.token && result.user) {
saveSession(result.token, result.user);
@@ -324,7 +324,7 @@ async function finishNqi() {
<p v-if="noticeVisible" class="lv-notice">请使用大数据平台账号登录</p>
<form class="lv-fields" @submit.prevent="submitLogin">
<label for="pool-account">账号</label>
<n-input :input-props="{ id: 'pool-account', autocomplete: 'username' }" v-model:value="username" @keyup.enter="submitLogin" />
<n-input :input-props="{ id: 'pool-account', autocomplete: 'username' }" v-model:value="username" :disabled="Boolean(account)" @keyup.enter="submitLogin" />
<label for="pool-password">密码</label>
<n-input :input-props="{ id: 'pool-password', autocomplete: 'current-password' }" v-model:value="password" type="password" show-password-on="click" @keyup.enter="submitLogin" />
<label for="pool-captcha">验证码</label>
@@ -335,7 +335,7 @@ async function finishNqi() {
<img v-else :src="captchaSrc" :class="{ broken: captchaSrc === BROKEN_CAPTCHA }" alt="验证码" @error="markCaptchaBroken" />
</button>
</div>
<n-button class="lv-go" type="primary" attr-type="submit" :loading="busy">添加</n-button>
<n-button class="lv-go" type="primary" attr-type="submit" :loading="busy">{{ account ? "登录" : "添加" }}</n-button>
</form>
</section>
<div v-else class="gate lv-tower">