get_row_prepare("SELECT * FROM MN_plugin_user WHERE id=? LIMIT 1", [$user_id]); if (!$user) { return null; } if ((int)$user['status'] !== 1) { return null; } $expected = md5($user['id'] . $user['password_hash'] . SYS_KEY); if ($session_hash !== $expected) { return null; } return $user; } /** * 要求登录,未登录跳转登录页。返回用户数组。 */ function user_info_auth_require() { $user = user_info_auth_current(); if (!$user) { header('Location: ' . user_info_url('account/login')); exit; } return $user; } /** * 解析主题提供的 account 入口文件(如 tdesign 主题的 SPA 入口)。 * 当前用户主题下存在 templates/{theme}/account/{view}.php 时返回路径,否则返回 null。 * * @param string $view views 名称:login/register/profile/password/dashboard * @return string|null */ function user_info_theme_entry($view) { if (!function_exists('mnbt_theme_name') || !defined('MNBT_THEME_ROOT')) { return null; } $map = [ 'login' => 'login.php', 'register' => 'register.php', 'profile' => 'profile.php', 'password' => 'password.php', 'dashboard' => 'index.php', ]; if (!isset($map[$view])) { return null; } $theme = mnbt_theme_name('user'); $file = MNBT_THEME_ROOT . $theme . '/account/' . $map[$view]; return is_file($file) ? $file : null; } /** * 渲染视图文件(带布局)。 * * 当前用户主题若提供 account 入口(如 tdesign SPA),优先交给主题渲染; * 否则回退到插件自带 Layui 布局。 * * @param string $view views 目录下的文件名(不含 .php) * @param array $vars 传给视图的变量 */ function user_info_render($view, $vars = []) { $vars['current_user'] = user_info_auth_current(); $vars['asset_url'] = user_info_asset_url(); $vars['url'] = 'user_info_url'; extract($vars, EXTR_SKIP); $themeEntry = user_info_theme_entry($view); if ($themeEntry !== null) { // 主题入口在函数作用域内 include,需要展开全局变量($conf/$DB/$date 等) extract($GLOBALS, EXTR_SKIP); include $themeEntry; return; } $viewFile = mnbt_plugin_path('user_info') . 'views/' . $view . '.php'; if (!is_file($viewFile)) { http_response_code(500); echo 'View not found: ' . htmlspecialchars($view); return; } include $viewFile; } /** * 输出 JSON 并退出。 */ function user_info_json($code, $extra = []) { @header('Content-Type: application/json; charset=UTF-8'); $payload = ['code' => $code]; if (is_array($extra)) { $payload = array_merge($payload, $extra); } echo json_encode($payload, JSON_UNESCAPED_UNICODE); exit; }