From fc8d367963a16de61dfbc4a0ff34c78c91ec2cfe Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 05 九月 2025 09:21:28 +0800
Subject: [PATCH] Merge branch 'liuyang' into clh
---
SourceCode/Bond/Servo/UserManager.h | 164 +++++++++++++++++++++++++++---------------------------
1 files changed, 83 insertions(+), 81 deletions(-)
diff --git a/SourceCode/Bond/Servo/UserManager.h b/SourceCode/Bond/Servo/UserManager.h
index 590b2e1..cd1f3cc 100644
--- a/SourceCode/Bond/Servo/UserManager.h
+++ b/SourceCode/Bond/Servo/UserManager.h
@@ -1,4 +1,4 @@
-#ifndef USER_MANAGER_H
+锘�#ifndef USER_MANAGER_H
#define USER_MANAGER_H
#include <string>
@@ -7,124 +7,126 @@
#include <windows.h>
#include "Database.h"
-// 用户角色定义
+// 鐢ㄦ埛瑙掕壊瀹氫箟
enum class UserRole {
- SuperAdmin = 0, // 超级管理员
- Engineer, // 工程师
- Operator // 操作员
+ SuperAdmin = 0, // 瓒呯骇绠$悊鍛橈細绯荤粺鏈�楂樻潈闄愶紝绠$悊鎵�鏈夌敤鎴峰拰鏉冮檺
+ ProcessEngineer, // 鍒剁▼宸ョ▼甯堬細璐熻矗宸ヨ壓鍒跺畾涓庝紭鍖�
+ EquipmentEngineer,// 璁惧宸ョ▼甯堬細璐熻矗璁惧缁存姢涓庢妧鏈敮鎸�
+ Operator, // 鎿嶄綔鍛橈細鎵ц鏃ュ父鐢熶骇鎿嶄綔
+ Unknown // 鏈煡瑙掕壊锛氶粯璁ゆ垨鏈瘑鍒殑瑙掕壊
};
-// 用户管理类,采用单例模式
+// 鐢ㄦ埛绠$悊绫伙紝閲囩敤鍗曚緥妯″紡
class UserManager {
public:
- static UserManager& getInstance();
+ static UserManager& getInstance();
- UserManager(const UserManager&) = delete;
- UserManager& operator=(const UserManager&) = delete;
+ UserManager(const UserManager&) = delete;
+ UserManager& operator=(const UserManager&) = delete;
- // 提供数据库连接
- std::unique_ptr<BL::Database>& getDatabaseInstance();
+ // 鎻愪緵鏁版嵁搴撹繛鎺�
+ std::unique_ptr<BL::Database>& getDatabaseInstance();
- // 用户操作
- bool login(const std::string& username, const std::string& password, bool rememberMe = false);
- void logout();
- bool isLoggedIn() const;
+ // 鐢ㄦ埛鎿嶄綔
+ bool login(const std::string& username, const std::string& password, bool rememberMe = false);
+ void logout();
+ bool isLoggedIn() const;
bool isRememberMe() const;
- bool createUser(const std::string& username, const std::string& password, UserRole role,
- std::chrono::minutes timeout = std::chrono::minutes(30),
- std::chrono::hours expiration = std::chrono::hours(72));
- bool deleteUser(const std::string& username);
- std::vector<std::vector<std::string>> getUsers();
- bool setUsers(const std::vector<std::vector<std::string>>& usersData);
- bool changeUsername(const std::string& username, const std::string& newUsername);
- bool changePassword(const std::string& username, const std::string& newPassword);
- bool changeUserRole(const std::string& username, UserRole newRole);
- bool changeUserSessionTimeout(const std::string& username, int newTimeoutMinutes);
- bool changeUserSessionExpiration(const std::string& username, int newExpirationHours);
- std::vector<std::string> getUsernames();
- std::vector<std::string> getUserInfo(const std::string& username);
+ bool createUser(const std::string& username, const std::string& password, UserRole role,
+ std::chrono::minutes timeout = std::chrono::minutes(30),
+ std::chrono::hours expiration = std::chrono::hours(72));
+ bool deleteUser(const std::string& username);
+ std::vector<std::vector<std::string>> getUsers();
+ bool setUsers(const std::vector<std::vector<std::string>>& usersData);
+ bool changeUsername(const std::string& username, const std::string& newUsername);
+ bool changePassword(const std::string& username, const std::string& newPassword);
+ bool changeUserRole(const std::string& username, UserRole newRole);
+ bool changeUserSessionTimeout(const std::string& username, int newTimeoutMinutes);
+ bool changeUserSessionExpiration(const std::string& username, int newExpirationHours);
+ std::vector<std::string> getUsernames();
+ std::vector<std::string> getUserInfo(const std::string& username);
- // 会话文件操作
- bool loadSession(); // 从会话文件加载会话信息
- void saveSession(); // 保存会话信息到文件
- void clearSession(); // 清除会话文件
+ // 浼氳瘽鏂囦欢鎿嶄綔
+ bool loadSession(); // 浠庝細璇濇枃浠跺姞杞戒細璇濅俊鎭�
+ void saveSession(); // 淇濆瓨浼氳瘽淇℃伅鍒版枃浠�
+ void clearSession(); // 娓呴櫎浼氳瘽鏂囦欢
- // 配置文件夹路径管理
- static std::string getConfigFolderPath();
- static std::string getSessionFilePath();
- static std::string getDatabaseFilePath();
+ // 閰嶇疆鏂囦欢澶硅矾寰勭鐞�
+ static std::string getConfigFolderPath();
+ static std::string getSessionFilePath();
+ static std::string getDatabaseFilePath();
- // 更新最后活动时间(用于无操作超时检测)
- void updateActivityTime();
+ // 鏇存柊鏈�鍚庢椿鍔ㄦ椂闂达紙鐢ㄤ簬鏃犳搷浣滆秴鏃舵娴嬶級
+ void updateActivityTime();
- // 设置用户的无操作超时时间
- void setSessionTimeout(std::chrono::minutes timeout);
+ // 璁剧疆鐢ㄦ埛鐨勬棤鎿嶄綔瓒呮椂鏃堕棿
+ void setSessionTimeout(std::chrono::minutes timeout);
- // 检查是否无操作超时
- bool isInactiveTimeout() const;
+ // 妫�鏌ユ槸鍚︽棤鎿嶄綔瓒呮椂
+ bool isInactiveTimeout() const;
- // 初始化无操作检测(设置全局钩子和定时器)
- void initializeIdleDetection(HWND hwnd);
+ // 鍒濆鍖栨棤鎿嶄綔妫�娴嬶紙璁剧疆鍏ㄥ眬閽╁瓙鍜屽畾鏃跺櫒锛�
+ void initializeIdleDetection(HWND hwnd);
- // 终止无操作检测(清除钩子和定时器)
- void terminateIdleDetection();
+ // 缁堟鏃犳搷浣滄娴嬶紙娓呴櫎閽╁瓙鍜屽畾鏃跺櫒锛�
+ void terminateIdleDetection();
- // 获取当前登录用户名
+ // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛鍚�
std::string getCurrentUser() const;
- // 修改当前登录用户名
- void setCurrentUser(const std::string& strName);
+ // 淇敼褰撳墠鐧诲綍鐢ㄦ埛鍚�
+ void setCurrentUser(const std::string& strName);
- // 获取当前登录用户密码
+ // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛瀵嗙爜
std::string getCurrentPass() const;
- // 修改当前登录用户密码
- void setCurrentPass(const std::string& strPass);
+ // 淇敼褰撳墠鐧诲綍鐢ㄦ埛瀵嗙爜
+ void setCurrentPass(const std::string& strPass);
- // 获取当前登录用户角色
+ // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛瑙掕壊
UserRole getCurrentUserRole() const;
- // 修改当前登录用户角色
- void setCurrentUserRole(UserRole emRole);
+ // 淇敼褰撳墠鐧诲綍鐢ㄦ埛瑙掕壊
+ void setCurrentUserRole(UserRole emRole);
- // 获取当前登录用户的无操作超时时间
+ // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛鐨勬棤鎿嶄綔瓒呮椂鏃堕棿
std::chrono::minutes getSessionTimeout() const;
- // 获取当前登录用户的会话过期时间
+ // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛鐨勪細璇濊繃鏈熸椂闂�
std::chrono::hours getSessionExpiration() const;
private:
- UserManager();
- ~UserManager();
+ UserManager();
+ ~UserManager();
- // 初始化数据库连接和用户表
- bool initializeDatabase();
+ // 鍒濆鍖栨暟鎹簱杩炴帴鍜岀敤鎴疯〃
+ bool initializeDatabase();
- // 哈希密码,用于加密用户密码
- std::string hashPassword(const std::string& password);
+ // 鍝堝笇瀵嗙爜锛岀敤浜庡姞瀵嗙敤鎴峰瘑鐮�
+ std::string hashPassword(const std::string& password);
- // 加密和解密函数
- std::string simpleEncryptDecrypt(const std::string& data, const std::string& key);
+ // 鍔犲瘑鍜岃В瀵嗗嚱鏁�
+ std::string simpleEncryptDecrypt(const std::string& data, const std::string& key);
- // 键盘和鼠标钩子函数
- static LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam);
- static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
+ // 閿洏鍜岄紶鏍囬挬瀛愬嚱鏁�
+ static LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam);
+ static LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
- // 属性定义
- std::string m_strCurrentUser; // 当前登录用户名
- std::string m_strCurrentPass; // 当前登录密码
- UserRole m_enCurrentUserRole; // 当前登录用户角色
- bool m_isLoggedIn; // 是否已登录
- bool m_isRememberMe; // 是否记住登录状态
+ // 灞炴�у畾涔�
+ std::string m_strCurrentUser; // 褰撳墠鐧诲綍鐢ㄦ埛鍚�
+ std::string m_strCurrentPass; // 褰撳墠鐧诲綍瀵嗙爜
+ UserRole m_enCurrentUserRole; // 褰撳墠鐧诲綍鐢ㄦ埛瑙掕壊
+ bool m_isLoggedIn; // 鏄惁宸茬櫥褰�
+ bool m_isRememberMe; // 鏄惁璁颁綇鐧诲綍鐘舵��
- std::chrono::time_point<std::chrono::system_clock> m_tpLastLogin; // 上次登录时间
- std::chrono::time_point<std::chrono::system_clock> m_tpLastActivity; // 最后活动时间
- std::chrono::minutes m_tmSessionTimeout; // 无操作超时时间
- std::chrono::hours m_tmSessionExpiration; // 会话过期时间
- HHOOK m_hMouseHook; // 鼠标钩子句柄
- HHOOK m_hKeyboardHook; // 键盘钩子句柄
+ std::chrono::time_point<std::chrono::system_clock> m_tpLastLogin; // 涓婃鐧诲綍鏃堕棿
+ std::chrono::time_point<std::chrono::system_clock> m_tpLastActivity; // 鏈�鍚庢椿鍔ㄦ椂闂�
+ std::chrono::minutes m_tmSessionTimeout; // 鏃犳搷浣滆秴鏃舵椂闂�
+ std::chrono::hours m_tmSessionExpiration; // 浼氳瘽杩囨湡鏃堕棿
+ HHOOK m_hMouseHook; // 榧犳爣閽╁瓙鍙ユ焺
+ HHOOK m_hKeyboardHook; // 閿洏閽╁瓙鍙ユ焺
- std::unique_ptr<BL::Database> m_pDB; // 数据库接口
+ std::unique_ptr<BL::Database> m_pDB; // 鏁版嵁搴撴帴鍙�
};
#endif // USER_MANAGER_H
\ No newline at end of file
--
Gitblit v1.9.3