- bootstrap.php/login.php:整体移除「5 次失败锁 10 分钟」限流,登录失败仅即时提示原因 - 新增 tools/fix-config.php:一键双写修正连接地址(默认 exam.nxxy335.top),清空账号密码让用户重输真实卷王凭据 - NY_DATA 隔离落地:run-all.sh 给写配置的 e2e 指向临时目录;修 Windows Git Bash /c/... 路径规范化 bug;.ny-test-data 加 .gitignore - 清理 dead throttle 引用(e2e 脚本 + docs) - 修 login.php 真实 bug:ny_is_auth() 分支在加载 $cfg 前引用导致 Undefined variable 警告 - 全量测试 116 通过(PHP 44 + e2e 72)
106 lines
4.0 KiB
PHP
106 lines
4.0 KiB
PHP
<?php
|
|
/**
|
|
* 独立登录页:连接信息(系统地址/接口前缀/账号)已在 data/config.json 中预置,
|
|
* 本页只需输入密码(账号可改)完成卷王登录,成功后进入主系统。
|
|
* 连接信息有变请在【设置】中修改。
|
|
*/
|
|
declare(strict_types=1);
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
// 先加载配置:下面已登录分支要用 $cfg 构造 SurveyKingClient 探活,必须在前面就准备好
|
|
$cfg = ny_load_config();
|
|
|
|
if (ny_is_auth()) {
|
|
// 已登录但卷王 token 可能已过期:用当前 token 探一次卷王 /system,能 200 即视为有效,否则清掉本地会话强制重新登录
|
|
try {
|
|
$client = new SurveyKingClient($cfg);
|
|
$client->ping();
|
|
} catch (Throwable $e) {
|
|
// 卷王 token 已失效或配置错误 → 清会话 + 强制显示登录页(避免 login.php 把人踢回 index.php 形成死循环)
|
|
$_SESSION = [];
|
|
@session_destroy();
|
|
}
|
|
if (ny_is_auth()) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$err = '';
|
|
$ok = false;
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$user = trim((string)($_POST['username'] ?? $cfg['username']));
|
|
$pwd = (string)($_POST['password'] ?? '');
|
|
// 允许用户在本页调整账号;密码必须输入
|
|
if ($user === '' || $pwd === '') {
|
|
$err = '请输入账号与密码。';
|
|
} else {
|
|
// 用当前配置的连接信息 + 本页输入的账密做一次卷王登录
|
|
$test = $cfg;
|
|
$test['username'] = $user;
|
|
$test['password'] = $pwd;
|
|
try {
|
|
$client = new SurveyKingClient($test);
|
|
$client->getToken(true);
|
|
// 登录成功:把账号与密码写回配置(本地单用户工具,持久化密码以便 token
|
|
// 失效时平台能自动重新登录卷王,避免后台刷新陷入"未配置账号"的死状态)
|
|
$cfg['username'] = $user;
|
|
$cfg['password'] = $pwd;
|
|
ny_save_config($cfg);
|
|
ny_login();
|
|
$ok = true;
|
|
} catch (Throwable $e) {
|
|
$err = '登录失败:' . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>登录 · <?= htmlspecialchars(NY_APP_NAME) ?></title>
|
|
<link rel="stylesheet" href="assets/style.css">
|
|
</head>
|
|
<body>
|
|
<div class="login-gate<?= $ok ? ' hidden' : '' ?>">
|
|
<div class="login-box">
|
|
<div class="login-brand">
|
|
<span class="logo">NY</span>
|
|
<div class="brand-text">
|
|
<strong><?= htmlspecialchars(NY_APP_NAME) ?></strong>
|
|
<small>实时数据统计</small>
|
|
</div>
|
|
</div>
|
|
<p class="login-tip">系统连接信息已配置(<?= htmlspecialchars(parse_url($cfg['base_url'], PHP_URL_HOST)) ?>/<?= htmlspecialchars(trim($cfg['api_prefix'], '/')) ?>)。请输入账号密码完成登录。</p>
|
|
|
|
<?php if ($err !== ''): ?>
|
|
<div class="alert" style="white-space:pre-wrap"><?= htmlspecialchars($err) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post">
|
|
<div class="fi"><label>账号</label><input type="text" name="username" value="<?= htmlspecialchars($cfg['username']) ?>" autocomplete="username"></div>
|
|
<div class="fi"><label>密码</label><input type="password" name="password" placeholder="请输入密码" autocomplete="current-password" autofocus></div>
|
|
<div class="login-actions">
|
|
<button class="btn btn-primary" type="submit">登录</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($ok): ?>
|
|
<div class="login-gate">
|
|
<div class="login-box" style="text-align:center">
|
|
<div class="login-brand" style="justify-content:center"><span class="logo">NY</span>
|
|
<div class="brand-text"><strong>登录成功</strong><small>正在进入数据平台…</small></div>
|
|
</div>
|
|
<script>setTimeout(function(){ location.href='index.php'; }, 600);</script>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
</body>
|
|
</html>
|