Skip to content

Commit

Permalink
[1.0.0.0]【正式版本!】发送消息支持Ctrl+Enter、优化登录逻辑,微调数据库结构,微调部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoFeng-QWQ committed Oct 4, 2024
1 parent 84b4b86 commit 3edb772
Show file tree
Hide file tree
Showing 37 changed files with 799 additions and 572 deletions.
27 changes: 13 additions & 14 deletions Admin/helper/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,44 @@
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/database_connection.php';

use ChatRoom\Core\Auth\CheckUserLoginStatus;
use ChatRoom\Core\Helpers\SystemSetting;

/**
* 初始化变量
*/
$cookieLoginToken = isset($_COOKIE['admin_login_info']) ? json_decode($_COOKIE['admin_login_info'], true)['login_token'] ?? '' : '';
$SystemSetting = new SystemSetting($db);
$loginStatus = new CheckUserLoginStatus;

/**
* 验证权限
*/
// 验证会话中的用户ID
$userId = $_SESSION['admin_login_info']['user_id'] ?? null;
if (!$loginStatus->check()) {
logoutAndRedirect();
}

$userId = $_SESSION['user_login_info']['user_id'] ?? null;
if ($userId === null) {
logoutAndRedirect();
}
// 查询数据库中的login_token和group_id
$stmt = $db->prepare('SELECT admin_login_token, group_id FROM users WHERE user_id = :user_id');
// 查询数据库中的group_id
$stmt = $db->prepare('SELECT group_id FROM users WHERE user_id = :user_id');
$stmt->execute(['user_id' => $userId]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// 检查数据库中的login_token是否与会话和cookie中的一致,以及用户是否为管理员
if (
$user === false ||
$user['admin_login_token'] !== $_SESSION['admin_login_info']['login_token'] ?? null ||
$user['admin_login_token'] !== $cookieLoginToken ?? null ||
$user['group_id'] != 1
) {
if ($user === false || $user['group_id'] != 1) {
logoutAndRedirect();
}
/**
* 登出并重定向到登录页面
*/
function logoutAndRedirect()
{
unset($_SESSION['admin_login_info']);
setcookie('admin_login_info', '', time() - 3600, '/'); // 删除cookie
unset($_SESSION['user_login_info']);
setcookie('user_login_info', '', time() - 3600, '/'); // 删除cookie

// 确保没有之前的输出,以便能够成功重定向
ob_clean();
header('Location: /Admin/login.php');
header('Location: /Admin/login.php?callBack=' . $_SERVER['REQUEST_URI']);
exit;
}
2 changes: 2 additions & 0 deletions Admin/helper/database_connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
try {
$db = new PDO('sqlite:' . FRAMEWORK_DATABASE_PATH);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec('PRAGMA journal_mode=WAL;');
$db->beginTransaction();
} catch (PDOException $e) {
throw new Exception('数据库错误:'. $e->getMessage());
}
121 changes: 0 additions & 121 deletions Admin/helper/login_verify.php

This file was deleted.

13 changes: 6 additions & 7 deletions Admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</div>
<div class="card-body">
<ul class="list-group list-group-flush">
<li class="list-group-item">2024-10-4:[1.0.0.0]【正式版本!】发送消息支持Ctrl+Enter、优化登录逻辑,微调数据库结构,微调部分代码</li>
<li class="list-group-item">2024-09-17:[1.10.0.0]添加指令系统、新消息通知音。微调部分代码</li>
<li class="list-group-item">2024-08-27: [1.9.0.0]支持发送图片消息。</li>
<li class="list-group-item">2024-08-26: [1.8.0.0]完善后台管理。</li>
Expand Down Expand Up @@ -154,24 +155,22 @@

// Chart.js 配置对象
const chartConfig = {
type: 'line',
type: 'bar', // 修改图表类型为柱状图
data: {
labels: trendLabels,
datasets: [{
label: '消息数',
data: messageTrendCounts,
borderColor: 'rgba(255, 99, 132, 1)', // 修改颜色为红色
backgroundColor: 'rgba(255, 99, 132, 0.2)', // 填充颜色
borderWidth: 1,
fill: true // 启用填充
borderColor: 'rgba(255, 99, 132, 1)', // 边框颜色
borderWidth: 1
},
{
label: '用户数',
data: userTrendCounts,
borderColor: 'rgba(75, 192, 192, 1)', // 修改颜色为绿色
backgroundColor: 'rgba(75, 192, 192, 0.2)', // 填充颜色
borderWidth: 1,
fill: true // 启用填充
borderColor: 'rgba(75, 192, 192, 1)', // 边框颜色
borderWidth: 1
}
]
},
Expand Down
Loading

0 comments on commit 3edb772

Please sign in to comment.