| | |
| | | SourceCode/Bond/x64/Debug/HsmsPassive.cache |
| | | SourceCode/Bond/x64/Debug/MasterState.dat |
| | | SourceCode/Bond/x64/Debug/Recipe/EQ10_Unit0.recipelist |
| | | SourceCode/Bond/UserX/ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #include "stdafx.h" |
| | | #include "CUserManager2.h" |
| | | #include "ToolUnits.h" |
| | | #include <sstream> |
| | | #include <cwchar> |
| | | |
| | | std::vector<std::wstring> SplitLines(const std::wstring& text) |
| | | { |
| | | std::wstringstream ss(text); std::vector<std::wstring> v; std::wstring line; while (std::getline(ss, line)) v.push_back(line); return v; |
| | | } |
| | | |
| | | template<typename Fn> |
| | | std::wstring ReadBufferVia(Fn fn) |
| | | { |
| | | int need = fn(nullptr, 0); if (need <= 0) return L""; |
| | | std::wstring buf; buf.resize((size_t)need); |
| | | int rc = fn(buf.data(), need); |
| | | if (rc == 0) { if (!buf.empty() && buf.back() == L'\0') buf.pop_back(); return buf; } |
| | | return L""; |
| | | } |
| | | |
| | | // è·ååä¾å®ä¾ |
| | | CUserManager2& CUserManager2::getInstance() { |
| | | static CUserManager2 instance; |
| | | return instance; |
| | | } |
| | | |
| | | CUserManager2::CUserManager2() |
| | | { |
| | | |
| | | } |
| | | |
| | | CUserManager2::~CUserManager2() |
| | | { |
| | | |
| | | } |
| | | |
| | | void CUserManager2::init(const char* pszDir) |
| | | { |
| | | std::wstring dir = CToolUnits::AnsiToWString(std::string(pszDir)); |
| | | UX_Init(dir.c_str()); |
| | | |
| | | wchar_t buffer[1024]; |
| | | UX_GetUsers(buffer, 1024); |
| | | bool hasAny = false; |
| | | for (auto& ln : SplitLines(buffer)) { if (!ln.empty()) { hasAny = true; break; } } |
| | | if (!hasAny) { |
| | | const wchar_t* roles = L"Admin:100\nEngineer:50\nOperator:10\n"; |
| | | (void)UX_SetRoleDefinitions(roles); |
| | | (void)UX_AddUser(L"admin", L"Administrator", L"admin123", L"Admin"); |
| | | } |
| | | } |
| | | |
| | | bool CUserManager2::login(const char* pszAccount, const char* pszPwd) |
| | | { |
| | | std::wstring strUser, strPwd; |
| | | strUser = CToolUnits::AnsiToWString(std::string(pszAccount)); |
| | | strPwd = CToolUnits::AnsiToWString(std::string(pszPwd)); |
| | | int rc = UX_Login(strUser.c_str(), strPwd.c_str()); |
| | | return rc == UX_OK; |
| | | } |
| | | |
| | | bool CUserManager2::isLoggedIn() |
| | | { |
| | | return UX_IsLoggedIn(); |
| | | } |
| | | |
| | | std::string CUserManager2::getCurrentUserName() |
| | | { |
| | | std::string strName; |
| | | |
| | | int need = UX_GetCurrentUser(nullptr, 0); |
| | | std::wstring buf; buf.resize((size_t)need); |
| | | if (UX_GetCurrentUser(buf.data(), need) == UX_OK) { |
| | | if (!buf.empty() && buf.back() == L'\0') |
| | | buf.pop_back(); |
| | | |
| | | strName = CToolUnits::WStringToAnsi(buf); |
| | | } |
| | | |
| | | return strName; |
| | | } |
| | | |
| | | bool CUserManager2::IsAdminCurrent() |
| | | { |
| | | if (UX_IsLoggedIn() != 1) return false; |
| | | int need = UX_GetCurrentUser(nullptr, 0); if (need <= 0) return false; |
| | | std::wstring user; user.resize((size_t)need); |
| | | if (UX_GetCurrentUser(user.data(), need) != 0) return false; |
| | | if (!user.empty() && user.back() == L'\0') user.pop_back(); |
| | | int maxLvl = 0; auto rolesTxt = ReadBufferVia([](wchar_t* b, int n) { return UX_GetRoles(b, n); }); |
| | | for (auto& ln : SplitLines(rolesTxt)) { size_t p = ln.find(L':'); if (p != std::wstring::npos) { int lvl = _wtoi(ln.substr(p + 1).c_str()); if (lvl > maxLvl) maxLvl = lvl; } } |
| | | int myLvl = 0; auto usersTxt = ReadBufferVia([](wchar_t* b, int n) { return UX_GetUsers(b, n); }); |
| | | for (auto& ln : SplitLines(usersTxt)) { |
| | | if (ln.empty()) continue; size_t p1 = ln.find(L','), p2 = ln.find(L',', p1 == std::wstring::npos ? 0 : p1 + 1), p3 = ln.find(L',', p2 == std::wstring::npos ? 0 : p2 + 1); |
| | | std::wstring name = (p1 == std::wstring::npos ? ln : ln.substr(0, p1)); if (name == user) { if (p2 != std::wstring::npos) { std::wstring lvlS = ln.substr(p2 + 1, (p3 == std::wstring::npos ? ln.size() : p3) - (p2 + 1)); myLvl = _wtoi(lvlS.c_str()); } break; } |
| | | } |
| | | |
| | | return (maxLvl > 0) && (myLvl >= maxLvl); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | class CUserManager2 |
| | | { |
| | | public: |
| | | static CUserManager2& getInstance(); |
| | | CUserManager2(const CUserManager2&) = delete; |
| | | CUserManager2& operator=(const CUserManager2&) = delete; |
| | | |
| | | public: |
| | | void init(const char* pszDir); |
| | | bool login(const char* pszAccount, const char* pszPwd); |
| | | bool isLoggedIn(); |
| | | std::string getCurrentUserName(); |
| | | bool IsAdminCurrent(); |
| | | |
| | | private: |
| | | CUserManager2(); |
| | | ~CUserManager2(); |
| | | }; |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // CUserManager2Dlg.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | #include "Servo.h" |
| | | #include "CUserManager2Dlg.h" |
| | | #include "afxdialogex.h" |
| | | |
| | | |
| | | // CUserManager2Dlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CUserManager2Dlg, CDialogEx) |
| | | |
| | | CUserManager2Dlg::CUserManager2Dlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_USER_MANAGER2, pParent) |
| | | { |
| | | |
| | | } |
| | | |
| | | CUserManager2Dlg::~CUserManager2Dlg() |
| | | { |
| | | } |
| | | |
| | | void CUserManager2Dlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CUserManager2Dlg, CDialogEx) |
| | | ON_WM_SIZE() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CUserManager2Dlg æ¶æ¯å¤çç¨åº |
| | | |
| | | |
| | | BOOL CUserManager2Dlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | |
| | | // TODO: 卿¤æ·»å é¢å¤çåå§å |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // å¼å¸¸: OCX 屿§é¡µåºè¿å FALSE |
| | | } |
| | | |
| | | void CUserManager2Dlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 卿¤å¤æ·»å æ¶æ¯å¤çç¨åºä»£ç |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | |
| | | |
| | | // CUserManager2Dlg å¯¹è¯æ¡ |
| | | |
| | | class CUserManager2Dlg : public CDialogEx |
| | | { |
| | | DECLARE_DYNAMIC(CUserManager2Dlg) |
| | | |
| | | public: |
| | | CUserManager2Dlg(CWnd* pParent = nullptr); // æ åæé 彿° |
| | | virtual ~CUserManager2Dlg(); |
| | | |
| | | // å¯¹è¯æ¡æ°æ® |
| | | #ifdef AFX_DESIGN_TIME |
| | | enum { IDD = IDD_DIALOG_USER_MANAGER2 }; |
| | | #endif |
| | | |
| | | protected: |
| | | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV æ¯æ |
| | | |
| | | DECLARE_MESSAGE_MAP() |
| | | public: |
| | | virtual BOOL OnInitDialog(); |
| | | afx_msg void OnSize(UINT nType, int cx, int cy); |
| | | }; |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // LoginDlg.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | | #include "stdafx.h" |
| | | #include "Servo.h" |
| | | #include "afxdialogex.h" |
| | | #include "LoginDlg2.h" |
| | | |
| | | |
| | | // CLoginDlg å¯¹è¯æ¡ |
| | | |
| | | IMPLEMENT_DYNAMIC(CLoginDlg2, CDialogEx) |
| | | |
| | | CLoginDlg2::CLoginDlg2(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_LOGIN, pParent) |
| | | { |
| | | } |
| | | |
| | | CLoginDlg2::~CLoginDlg2() |
| | | { |
| | | } |
| | | |
| | | void CLoginDlg2::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CLoginDlg2, CDialogEx) |
| | | ON_BN_CLICKED(IDC_BUTTON_LOGIN, &CLoginDlg2::OnBnClickedLogin) |
| | | ON_STN_CLICKED(IDC_STATIC_CHANGE_PASSWORD, &CLoginDlg2::OnBnClickedChangePassword) |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CLoginDlg æ¶æ¯å¤çç¨åº |
| | | |
| | | |
| | | BOOL CLoginDlg2::OnInitDialog() |
| | | { |
| | | CDialog::OnInitDialog(); |
| | | |
| | | // 设置çªå£æ é¢ååå§å¼ |
| | | SetWindowText(_T("ç»å½")); |
| | | |
| | | |
| | | CStatic* pStaticImage = (CStatic*)GetDlgItem(IDC_STATIC_IMAGE); |
| | | ASSERT(pStaticImage); |
| | | |
| | | CString strIconPath; |
| | | strIconPath.Format(_T("%s\\Res\\Operator_High_32.ico"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir); |
| | | HICON hIcon = (HICON)::LoadImage( |
| | | nullptr, |
| | | strIconPath, |
| | | IMAGE_ICON, |
| | | 32, // 徿 宽度 |
| | | 32, // 徿 é«åº¦ |
| | | LR_LOADFROMFILE); |
| | | if (hIcon) { |
| | | // 设置 CStatic æ§ä»¶ä¸ºå¾æ æ ·å¼ |
| | | pStaticImage->ModifyStyle(0xF, SS_ICON); |
| | | pStaticImage->SetIcon(hIcon); |
| | | } |
| | | |
| | | // æ·»å SS_NOTIFYæ ·å¼ |
| | | CStatic* pStatic = (CStatic*)GetDlgItem(IDC_STATIC_CHANGE_PASSWORD); |
| | | if (pStatic != nullptr) { |
| | | pStatic->ModifyStyle(0, SS_NOTIFY); |
| | | } |
| | | |
| | | GetDlgItem(IDC_CHECK_REMEMBER_PASSWORD)->ShowWindow(SW_HIDE); |
| | | |
| | | return TRUE; |
| | | } |
| | | |
| | | void CLoginDlg2::OnBnClickedLogin() |
| | | { |
| | | GetDlgItemText(IDC_EDIT_USERNAME, m_strUsername); |
| | | GetDlgItemText(IDC_EDIT_PASSWORD, m_strPassword); |
| | | |
| | | if (m_strUsername.IsEmpty()) { |
| | | AfxMessageBox(_T("请è¾å
¥ç¨æ·å")); |
| | | GetDlgItem(IDC_EDIT_USERNAME)->SetFocus(); |
| | | return; |
| | | } |
| | | if (m_strPassword.IsEmpty()) { |
| | | AfxMessageBox(_T("请è¾å
¥å¯ç ")); |
| | | GetDlgItem(IDC_EDIT_PASSWORD)->SetFocus(); |
| | | return; |
| | | } |
| | | |
| | | |
| | | EndDialog(IDOK); |
| | | } |
| | | |
| | | void CLoginDlg2::OnBnClickedChangePassword() |
| | | { |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | #include "afxdialogex.h" |
| | | |
| | | |
| | | // CLoginDlg å¯¹è¯æ¡ |
| | | |
| | | class CLoginDlg2 : public CDialogEx |
| | | { |
| | | DECLARE_DYNAMIC(CLoginDlg2) |
| | | |
| | | public: |
| | | CLoginDlg2(CWnd* pParent = nullptr); // æ åæé 彿° |
| | | virtual ~CLoginDlg2(); |
| | | |
| | | // å¯¹è¯æ¡æ°æ® |
| | | #ifdef AFX_DESIGN_TIME |
| | | enum { IDD = IDD_DIALOG_LOGIN }; |
| | | #endif |
| | | |
| | | public: |
| | | CString m_strUsername; |
| | | CString m_strPassword; |
| | | |
| | | protected: |
| | | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV æ¯æ |
| | | virtual BOOL OnInitDialog(); |
| | | afx_msg void OnBnClickedLogin(); |
| | | afx_msg void OnBnClickedChangePassword(); |
| | | DECLARE_MESSAGE_MAP() |
| | | }; |
| | |
| | | #include "MapPosWnd.h" |
| | | #include "HmTab.h" |
| | | #include "CControlJobManagerDlg.h" |
| | | #include "ToolUnits.h" |
| | | #include "CUserManager2.h" |
| | | |
| | | |
| | | // 声æå
¨å±åéï¼ç¨äºç®¡ç GDI+ åå§å |
| | |
| | | m_strAppDir = CString(sDrive) + CString(sDir); |
| | | m_strAppFile = CString(sFilename); |
| | | m_model.setWorkDir((LPTSTR)(LPCTSTR)m_strAppDir); |
| | | |
| | | |
| | | // ç¨æ·æ°æ®åºç®¡ç |
| | | CString strDir = m_strAppDir + _T("\\DB"); |
| | | CUserManager2::getInstance().init((LPTSTR)(LPCTSTR)strDir); |
| | | |
| | | |
| | | // æ³¨åæ§ä»¶ |
| | |
| | | m_model.term(); |
| | | HSMS_Term(); |
| | | RX_Term(); |
| | | UX_Shutdown(); |
| | | |
| | | // æ¸
ç GDI+ |
| | | TermGDIPlus(); |
| | |
| | | <ClInclude Include="CRobotTaskDlg.h" /> |
| | | <ClInclude Include="CSVData.h" /> |
| | | <ClInclude Include="CServoUtilsTool.h" /> |
| | | <ClInclude Include="CUserManager2.h" /> |
| | | <ClInclude Include="CUserManager2Dlg.h" /> |
| | | <ClInclude Include="CVariable.h" /> |
| | | <ClInclude Include="DeviceRecipeParamDlg.h" /> |
| | | <ClInclude Include="GlassJson.h" /> |
| | |
| | | <ClInclude Include="InputDialog.h" /> |
| | | <ClInclude Include="JobSlotGrid.h" /> |
| | | <ClInclude Include="LoginDlg.h" /> |
| | | <ClInclude Include="LoginDlg2.h" /> |
| | | <ClInclude Include="MsgDlg.h" /> |
| | | <ClInclude Include="PageRecipe.h" /> |
| | | <ClInclude Include="CDoubleGlass.h" /> |
| | |
| | | <ClCompile Include="CRobotTaskDlg.cpp" /> |
| | | <ClCompile Include="CSVData.cpp" /> |
| | | <ClCompile Include="CServoUtilsTool.cpp" /> |
| | | <ClCompile Include="CUserManager2.cpp" /> |
| | | <ClCompile Include="CUserManager2Dlg.cpp" /> |
| | | <ClCompile Include="CVariable.cpp" /> |
| | | <ClCompile Include="DeviceRecipeParamDlg.cpp" /> |
| | | <ClCompile Include="GlassJson.cpp" /> |
| | |
| | | <ClCompile Include="InputDialog.cpp" /> |
| | | <ClCompile Include="JobSlotGrid.cpp" /> |
| | | <ClCompile Include="LoginDlg.cpp" /> |
| | | <ClCompile Include="LoginDlg2.cpp" /> |
| | | <ClCompile Include="MsgDlg.cpp" /> |
| | | <ClCompile Include="PageRecipe.cpp" /> |
| | | <ClCompile Include="CDoubleGlass.cpp" /> |
| | |
| | | <ClCompile Include="..\DAQBridge\proto\ProtocolCodec.cpp"> |
| | | <Filter>DAQBridge</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="ClientListDlg.cpp" /> |
| | | <ClCompile Include="LoginDlg2.cpp" /> |
| | | <ClCompile Include="CUserManager2.cpp" /> |
| | | <ClCompile Include="CUserManager2Dlg.cpp" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClInclude Include="AlarmManager.h" /> |
| | |
| | | <ClInclude Include="..\DAQBridge\DAQConfig.h"> |
| | | <Filter>DAQBridge</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="ClientListDlg.h" /> |
| | | <ClInclude Include="LoginDlg2.h" /> |
| | | <ClInclude Include="CUserManager2.h" /> |
| | | <ClInclude Include="CUserManager2Dlg.h" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ResourceCompile Include="Servo.rc" /> |
| | |
| | | #include "CRobotCmdContainerDlg.h" |
| | | #include "CRobotCmdTestDlg.h" |
| | | #include "LoginDlg.h" |
| | | #include "LoginDlg2.h" |
| | | #include "ChangePasswordDlg.h" |
| | | #include "UserManagerDlg.h" |
| | | #include "SystemLogManagerDlg.h" |
| | |
| | | #include "InputDialog.h" |
| | | #include "ClientListDlg.h" |
| | | #include "CControlJobManagerDlg.h" |
| | | #include "CUserManager2.h" |
| | | #include "CUserManager2Dlg.h" |
| | | |
| | | |
| | | #ifdef _DEBUG |
| | |
| | | #define TIMER_ID_UPDATE_RUMTIME 2 |
| | | |
| | | /* Test */ |
| | | #define TIMER_ID_TEST 3 |
| | | #define TIMER_ID_LOGIN 3 |
| | | |
| | | |
| | | // ç¨äºåºç¨ç¨åºâå
³äºâèå项ç CAboutDlg å¯¹è¯æ¡ |
| | |
| | | |
| | | // model init |
| | | theApp.m_model.init(); |
| | | SetTimer(TIMER_ID_TEST, 1000, nullptr); |
| | | SetTimer(TIMER_ID_LOGIN, 1000, nullptr); |
| | | |
| | | // èå |
| | | CMenu menu; |
| | |
| | | m_pMyStatusbar->setRunTimeText((LPTSTR)(LPCTSTR)strText); |
| | | } |
| | | |
| | | else if(TIMER_ID_TEST == nIDEvent){ |
| | | static __int64 tttt = 0; |
| | | tttt++; |
| | | theApp.m_model.m_hsmsPassive.setVariableValue("CJobSpace", tttt % 10); |
| | | theApp.m_model.m_hsmsPassive.setVariableValue("PJobSpace", tttt % 5); |
| | | else if(TIMER_ID_LOGIN == nIDEvent){ |
| | | KillTimer(TIMER_ID_LOGIN); |
| | | if (!CUserManager2::getInstance().isLoggedIn()) { |
| | | CLoginDlg2 dlg; |
| | | if (dlg.DoModal() != IDOK) { |
| | | PostMessage(WM_CLOSE); |
| | | } |
| | | else { |
| | | bool bRet = CUserManager2::getInstance().login((LPTSTR)(LPCTSTR)dlg.m_strUsername, |
| | | (LPTSTR)(LPCTSTR)dlg.m_strPassword); |
| | | if (!bRet) { |
| | | AfxMessageBox("ç»å½å¤±è´¥ï¼è¯·æ£æ¥ç¨æ·åæå¯ç æ¯å¦æ£ç¡®ï¼"); |
| | | PostMessage(WM_CLOSE); |
| | | } |
| | | UpdateLoginStatus(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | void CServoDlg::UpdateLoginStatus() |
| | | { |
| | | HMENU hMenu = m_pTopToolbar->GetOperatorMenu(); |
| | | UserManager& userManager = UserManager::getInstance(); |
| | | if (userManager.isLoggedIn()) |
| | | { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_ENABLED); |
| | | CUserManager2& userManager = CUserManager2::getInstance(); |
| | | if (userManager.isLoggedIn()) { |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_ENABLED); |
| | | |
| | | if (userManager.getCurrentUserRole() == UserRole::SuperAdmin) { |
| | | if (userManager.IsAdminCurrent()) { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_ENABLED); |
| | | } |
| | | else { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | } |
| | | |
| | | m_pTopToolbar->SetOperatorBtnText(userManager.getCurrentUser().c_str()); |
| | | m_pTopToolbar->SetOperatorBtnText(userManager.getCurrentUserName().c_str()); |
| | | } |
| | | else { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | |
| | | m_pTopToolbar->SetOperatorBtnText(_T("æªç»å½")); |
| | | } |
| | | } |
| | |
| | | } |
| | | else if (id == IDC_BUTTON_OPERATOR) { |
| | | int menuId = (int)wParam; |
| | | if (menuId == 0) { |
| | | CUserManager2Dlg dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | |
| | | |
| | | /* |
| | | SystemLogManager& logManager = SystemLogManager::getInstance(); |
| | | UserManager& userManager = UserManager::getInstance(); |
| | | if (menuId == 0) { |
| | |
| | | } |
| | | |
| | | UpdateLoginStatus(); |
| | | */ |
| | | } |
| | | |
| | | return 0; |
| | |
| | | oss << std::put_time(&tm, "%Y%m%d%H%M%S"); // ä¾ï¼2025-09-15 08:23:07 |
| | | return oss.str(); |
| | | } |
| | | |
| | | std::wstring CToolUnits::AnsiToWString(const std::string& str) |
| | | { |
| | | if (str.empty()) return std::wstring(); |
| | | |
| | | int len = ::MultiByteToWideChar(CP_ACP, 0, |
| | | str.c_str(), -1, |
| | | nullptr, 0); |
| | | if (len <= 0) return std::wstring(); |
| | | |
| | | std::wstring ws; |
| | | ws.resize(len - 1); |
| | | |
| | | ::MultiByteToWideChar(CP_ACP, 0, |
| | | str.c_str(), -1, |
| | | &ws[0], len); |
| | | |
| | | return ws; |
| | | } |
| | | |
| | | std::string CToolUnits::WStringToAnsi(const std::wstring& wstr) |
| | | { |
| | | if (wstr.empty()) return std::string(); |
| | | |
| | | int len = ::WideCharToMultiByte(CP_ACP, 0, |
| | | wstr.c_str(), -1, |
| | | nullptr, 0, |
| | | nullptr, nullptr); |
| | | if (len <= 0) return std::string(); |
| | | |
| | | std::string str; |
| | | str.resize(len - 1); |
| | | |
| | | ::WideCharToMultiByte(CP_ACP, 0, |
| | | wstr.c_str(), -1, |
| | | &str[0], len, |
| | | nullptr, nullptr); |
| | | |
| | | return str; |
| | | } |
| | |
| | | const char* fmt = "%Y-%m-%d %H:%M:%S"); |
| | | static std::string TimePointToLocalStringMs(const std::optional<TP>& tp); |
| | | static std::string NowStrSec(); |
| | | static std::wstring AnsiToWString(const std::string& str); |
| | | static std::string WStringToAnsi(const std::wstring& wstr); |
| | | }; |
| | | |
| | |
| | | |
| | | #include "..\RxWindows1.0\include\RxWindowsLib.h" |
| | | #include "..\HSMSSDK\Include\HSMSSDK.h" |
| | | |
| | | #include "..\UserXLibrary\UserXAPI.h" |
| | | |
| | | |
| | | #ifdef _UNICODE |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | // UserX ç¨æ·ç®¡çåºï¼C æ¥å£ï¼/ UserX user management library (C API) |
| | | // è¦çåè½ / Features: users, roles, actions, auth, logsï¼åºå® SQLite3 æä¹
å / SQLite3 persistenceï¼ |
| | | |
| | | #pragma once |
| | | |
| | | #if defined(_WIN32) |
| | | # ifdef USERXLIBRARY_EXPORTS |
| | | # define UX_API extern "C" __declspec(dllexport) |
| | | # else |
| | | # define UX_API extern "C" __declspec(dllimport) |
| | | # endif |
| | | #else |
| | | # define UX_API extern "C" |
| | | #endif |
| | | |
| | | #include <wchar.h> |
| | | |
| | | |
| | | #ifdef _COMPILE_AS_LIB |
| | | #warning "compiling as lib!" |
| | | #else |
| | | #ifdef _DEBUG |
| | | #ifndef _WIN64 |
| | | #pragma comment(lib, "../USERXLibrary/lib/Win32/Debug/UserXLibrary.lib") |
| | | #else |
| | | #pragma comment(lib, "../USERXLibrary/lib/x64/Debug/UserXLibrary.lib") |
| | | #endif |
| | | #else |
| | | #ifndef _WIN64 |
| | | #pragma comment(lib, "../USERXLibrary/lib/Win32/Release/UserXLibrary.lib") |
| | | #else |
| | | #pragma comment(lib, "../USERXLibrary/lib/x64/Release/UserXLibrary.lib") |
| | | #endif |
| | | #endif |
| | | #endif // !BUILD_AS_LIB |
| | | |
| | | |
| | | // é¢å¤é误ç / Extra error code |
| | | #ifndef UX_ERR_BAD_PASSWORD |
| | | #define UX_ERR_BAD_PASSWORD -10 // å¯ç é误 / bad password |
| | | #endif |
| | | |
| | | // é误ç å®å®ä¹ / Error code macros |
| | | #define UX_OK 0 // æå / success |
| | | #define UX_ERR_INVALID_ARGS -1 // åæ°é误 / invalid arguments |
| | | #define UX_ERR_NOT_FOUND -2 // æªæ¾å° / not found |
| | | #define UX_ERR_EXISTS -3 // å·²åå¨ / already exists |
| | | #define UX_ERR_PERMISSION -4 // æéä¸è¶³ / permission denied |
| | | #define UX_ERR_NOT_LOGGED_IN -5 // æªç»å½ / not logged in |
| | | #define UX_ERR_BUFFER_TOO_SMALL -6 // ç¼å²åºä¸è¶³ / buffer too small |
| | | #define UX_ERR_DB -7 // I/O ææ°æ®åºé误 / I/O or database error |
| | | #define UX_ERR_NOT_DEFINED -8 // æªå®ä¹ï¼å¦å¨ä½ä¸åå¨ï¼/ not defined |
| | | #define UX_ERR_DB_NOT_EMPTY -9 // æ°æ®åºé空ï¼å·²åå§åï¼/ database not empty |
| | | |
| | | // è¿åç / Return codesï¼è¯¦è§ä¸æ¹å®ï¼ |
| | | // UX_OK, UX_ERR_INVALID_ARGS, UX_ERR_NOT_FOUND, UX_ERR_EXISTS, |
| | | // UX_ERR_PERMISSION, UX_ERR_NOT_LOGGED_IN, UX_ERR_BUFFER_TOO_SMALL, |
| | | // UX_ERR_DB, UX_ERR_NOT_DEFINED, UX_ERR_DB_NOT_EMPTY |
| | | |
| | | // åå§åï¼æå®æ°æ®ç®å½ï¼å
é¨å°æå¼/å建 SQLite æ°æ®åºæä»¶ UserX.db |
| | | // Init: provide data directory; opens/creates SQLite DB file UserX.db |
| | | UX_API int UX_Init(const wchar_t* storage_dir); |
| | | |
| | | // å¯éï¼è¦çæ°æ®åºè·¯å¾ï¼ä»
使ç¨ç¬¬ä¸ä¸ªåæ°ä½ä¸º .db æä»¶è·¯å¾ï¼å
¶ä»å¿½ç¥ï¼ |
| | | // Optional: override DB path (use first arg as .db path; others ignored) |
| | | UX_API int UX_SetStorage(const wchar_t* users_db_path, |
| | | const wchar_t* /*unused_logs*/, |
| | | const wchar_t* /*unused_roles*/, |
| | | const wchar_t* /*unused_actions*/); |
| | | |
| | | // é
ç½®è§è²ï¼name:level æè¡ï¼/ Configure roles from lines "name:level" |
| | | // ä»
å
许å¨âç©ºæ°æ®åºâï¼roles/users/actions/logs åè¡¨åæ æ°æ®ï¼æ¶è°ç¨ï¼å¦åè¿å -9ã |
| | | // Only allowed when DB is empty (roles/users/actions/logs all zero rows); otherwise returns -9. |
| | | // e.g. L"Admin:100\nEngineer:50\nOperator:10\n" |
| | | UX_API int UX_SetRoleDefinitions(const wchar_t* roles_text); |
| | | |
| | | // è·åè§è²å表ï¼name:level æè¡ï¼ï¼buffer 为空æä¸è¶³æ¶è¿åæéå¤§å° |
| | | // Get roles list as lines; returns required size if buffer is null/too small |
| | | UX_API int UX_GetRoles(wchar_t* buffer, int buffer_chars); |
| | | |
| | | // ç¨æ·ç®¡ç / User management |
| | | UX_API int UX_AddUser(const wchar_t* username, |
| | | const wchar_t* display_name, |
| | | const wchar_t* password, |
| | | const wchar_t* role_name); |
| | | |
| | | UX_API int UX_DeleteUser(const wchar_t* username); |
| | | |
| | | // æ´æ°ä»»æå段ï¼ä¼ nullptr è¡¨ç¤ºä¿æä¸åï¼/ Update subset; nullptr keeps field |
| | | UX_API int UX_UpdateUser(const wchar_t* username, |
| | | const wchar_t* new_display_name, |
| | | const wchar_t* new_password, |
| | | const wchar_t* new_role_name, |
| | | int enabled /* -1 keep, 0 disable, 1 enable */); |
| | | |
| | | UX_API int UX_EnableUser(const wchar_t* username, int enabled /*0/1*/); |
| | | UX_API int UX_ResetPassword(const wchar_t* username, const wchar_t* new_password); |
| | | UX_API int UX_RenameUser(const wchar_t* username, const wchar_t* new_display_name); |
| | | |
| | | // 管çåæéï¼å 餿æç¨æ· / Admin-only |
| | | UX_API int UX_DeleteAllUsers(); |
| | | |
| | | // è·åç¨æ·åè¡¨ï¼æ¯è¡ï¼username,display,level,enabledï¼/ Query users |
| | | UX_API int UX_GetUsers(wchar_t* buffer, int buffer_chars); |
| | | |
| | | // è®¤è¯ / Authentication |
| | | UX_API int UX_Login(const wchar_t* username, const wchar_t* password); |
| | | UX_API void UX_Logout(); |
| | | UX_API int UX_IsLoggedIn(); |
| | | UX_API void UX_Shutdown(); // éæ¾èµæº / shutdown and free resources |
| | | UX_API int UX_GetCurrentUser(wchar_t* buffer, int buffer_chars); |
| | | |
| | | // å¨ä½ä¸æé / Actions & permissions |
| | | // å®ä¹/è¦çå¨ä½ï¼åç§°ãæè¿°ãæä½è§è²ï¼/ Define/overwrite action |
| | | UX_API int UX_DefineAction(const wchar_t* action_name, |
| | | const wchar_t* description, |
| | | const wchar_t* min_role_name); |
| | | |
| | | // 坿§è¡è¿å1ï¼ä¸å¯æ§è¡è¿å0ï¼è´æ°ä¸ºé误 / 1 allowed, 0 denied |
| | | UX_API int UX_CanExecute(const wchar_t* action_name); |
| | | |
| | | // è®°å½å¨ä½å°æ¥å¿ï¼æ¶é´ãç¨æ·ãå¨ä½ãæè¿°ï¼/ Record action to logs |
| | | UX_API int UX_RecordAction(const wchar_t* action_name); |
| | | |
| | | // è·åå¨ä½åè¡¨ï¼æ¯è¡ï¼name,desc,minlevelï¼/ Get actions list |
| | | UX_API int UX_GetActions(wchar_t* buffer, int buffer_chars); |
| | | |
| | | // è®°å½å°è¯ï¼å
许/æç»ï¼/ record an attempt with allowed flag (1 allowed, 0 denied) |
| | | UX_API int UX_RecordAttempt(const wchar_t* action_name, int allowed /*1/0*/); |
| | | |
| | | // æ¥è¯¢æè¿ N æ¡æ¥å¿ï¼æ¯è¡ï¼ISO8601æ¶é´,ç¨æ·å,å¨ä½,æè¿°ï¼/ Query logs |
| | | UX_API int UX_QueryLogs(int last_n, wchar_t* buffer, int buffer_chars); |
| | | |
| | | // æ ¹æ®é误ç è¿åæåæè¿°ï¼ä¸æ/Englishï¼ |
| | | // Return a human-readable message for an error code |
| | | UX_API const wchar_t* UX_ErrorMessage(int code); |