LAPTOP-T815PCOQ\25526
2024-11-20 8dbd14952aa622587a92866dc01943869ea4f9dc
SourceCode/Bond/BondEq/DBManager/UserManager.cpp
@@ -29,6 +29,11 @@
    terminateIdleDetection();
}
// 提供数据库连接
std::unique_ptr<BL::Database>& UserManager::getDatabaseInstance() {
    return m_pDB;
}
// 初始化数据库,创建用户表并插入初始管理员用户
bool UserManager::initializeDatabase() {
    std::string dbFilePath = getDatabaseFilePath();
@@ -293,7 +298,7 @@
        }
        std::string insertQuery = "INSERT INTO users (username, password, role, session_timeout, session_expiration, last_login) VALUES ('" +
            user[0] + "', '" + user[1] + "', " + user[2] + ", " + user[3] + ", " + user[4] + ", '" + user[5] + "')";
            user[0] + "', '" + simpleEncryptDecrypt(user[1], "BandKey") + "', " + user[2] + ", " + user[3] + ", " + user[4] + ", '" + user[5] + "')";
        if (!m_pDB->executeQuery(insertQuery)) {
            std::cerr << "Failed to insert user: " << user[0] << std::endl;
@@ -450,16 +455,31 @@
   return m_strCurrentUser;
}
// 修改当前登录用户名
void UserManager::setCurrentUser(const std::string& strName) {
    m_strCurrentUser = strName;
}
// 获取当前登录用户密码
std::string UserManager::getCurrentPass() const {
   return m_strCurrentPass;
}
// 修改当前登录用户密码
void UserManager::setCurrentPass(const std::string& strPass) {
    m_strCurrentPass = strPass;
}
// 获取当前登录用户角色
UserRole UserManager::getCurrentUserRole() const {
   return m_enCurrentUserRole;
}
// 修改当前登录用户角色
void UserManager::setCurrentUserRole(UserRole emRole) {
    m_enCurrentUserRole = emRole;
}
// 获取当前登录用户的无操作超时时间
std::chrono::minutes UserManager::getSessionTimeout() const {
   return m_tmSessionTimeout;