LoginDlg.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // MainDlg.cpp : implementation of the CLoginDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "LoginDlg.h"
  6. #include "StabtypeControl.h"
  7. #include "CApp.h"
  8. #include "CNetWork.h"
  9. CLoginDlg::CLoginDlg() : SHostWnd(_T("LAYOUT:XML_LOGIN"))
  10. {
  11. m_bLayoutInited = FALSE;
  12. }
  13. CLoginDlg::~CLoginDlg()
  14. {
  15. }
  16. int CLoginDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  17. {
  18. SetMsgHandled(FALSE);
  19. return 0;
  20. }
  21. BOOL CLoginDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
  22. {
  23. m_bLayoutInited = TRUE;
  24. Init();
  25. return 0;
  26. }
  27. void CLoginDlg::Init()
  28. {
  29. //if (m_network_tools == nullptr)
  30. //{
  31. // m_network_tools = new CManageNetWork();
  32. // //m_network_tools.Attach(new CManageNetWork());
  33. // m_network_tools->init();
  34. //}
  35. CManageNetWork::getSingletonPtr()->init();
  36. ServerListUrl list;
  37. list.id = 0;
  38. list.name = L"首选";
  39. list.url = "https://api.ruanjian.buzz";
  40. ServerListUrl list1;
  41. list1.id = 1;
  42. list1.name = L"备用1";
  43. list1.url = "https://api.ruanjian1.buzz";
  44. ServerListUrl list2;
  45. list2.id = 2;
  46. list2.name = L"备用2";
  47. list2.url = "https://ruanjian2.xyz";
  48. vctInfo.push_back(list);
  49. vctInfo.push_back(list1);
  50. vctInfo.push_back(list2);
  51. StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"nodeclass");
  52. if (tabtype)
  53. {
  54. for (auto i = 0; i < vctInfo.size(); i++)
  55. {
  56. tabtype->ItemCreateChildren(vctInfo[i].id, vctInfo[i].name, i == 0 ? true : false);
  57. }
  58. if (vctInfo.size() > 0)
  59. {
  60. CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[0].url.c_str());
  61. //Curl::getSingletonPtr()->SetUrl(vctInfo[0].url);
  62. }
  63. tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  64. Subscriber(&CLoginDlg::OnTabtypeControl, this));
  65. }
  66. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  67. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  68. if (m_edit_username) {
  69. m_edit_username->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetUsername()));
  70. m_edit_username->Invalidate();
  71. }
  72. if (m_edit_password)
  73. {
  74. m_edit_password->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetPassWord()));
  75. m_edit_password->Invalidate();
  76. }
  77. }
  78. bool CLoginDlg::OnTabtypeControl(SOUI::EventArgs* pEvt)
  79. {
  80. SOUI::EventTabtypeControl* pTestControlEvent =
  81. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  82. CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  83. /*if (m_curl)
  84. {
  85. m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  86. }*/
  87. //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
  88. return true;
  89. }
  90. //TODO:消息映射
  91. void CLoginDlg::OnClose()
  92. {
  93. CSimpleWnd::DestroyWindow();
  94. }
  95. void CLoginDlg::OnMaximize()
  96. {
  97. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  98. }
  99. void CLoginDlg::OnRestore()
  100. {
  101. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  102. }
  103. void CLoginDlg::OnMinimize()
  104. {
  105. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  106. }
  107. void CLoginDlg::OnLogin()
  108. {
  109. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  110. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  111. if (m_edit_username && m_edit_password)
  112. {
  113. auto username = m_edit_username->GetWindowTextW();
  114. auto password = m_edit_password->GetWindowTextW();
  115. /*if (m_base_curl) {
  116. char data[256] = { 0 };
  117. HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
  118. SLOG_DEBUG(data);
  119. }*/
  120. CManageNetWork::getSingletonPtr()->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  121. }
  122. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  123. if (onlogin)
  124. {
  125. onlogin->SetWindowTextW(L"正在登录...");
  126. onlogin->EnableWindow(FALSE);
  127. onlogin->Invalidate();
  128. }
  129. /**/
  130. }
  131. void CLoginDlg::ToMain()
  132. {
  133. CApp::getSingletonPtr()->SetOut(1);
  134. CSimpleWnd::DestroyWindow();
  135. }
  136. void CLoginDlg::OnLoginFinish(EventArgs* e)
  137. {
  138. EventLogin* e2 = sobj_cast<EventLogin>(e);
  139. if (!e2)
  140. {
  141. return;
  142. }
  143. if (e2->status == 0)
  144. {
  145. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  146. if (onlogin)
  147. {
  148. onlogin->SetWindowTextW(e2->msg);
  149. onlogin->EnableWindow(TRUE);
  150. onlogin->Invalidate();
  151. }
  152. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  153. } else if (e2->status == -1)
  154. {
  155. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  156. if (onlogin)
  157. {
  158. onlogin->SetWindowTextW(e2->msg);
  159. onlogin->EnableWindow(TRUE);
  160. onlogin->Invalidate();
  161. }
  162. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  163. ::ShellExecute(NULL, _T("open"), L"https://user.vipone.xyz/", NULL, NULL, SW_SHOWNORMAL);
  164. }
  165. else if (e2->status == -2) //用户到期
  166. {
  167. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  168. if (onlogin)
  169. {
  170. onlogin->SetWindowTextW(e2->msg);
  171. onlogin->EnableWindow(TRUE);
  172. onlogin->Invalidate();
  173. }
  174. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  175. ::ShellExecute(NULL, _T("open"), L"https://user.vipone.xyz/", NULL, NULL, SW_SHOWNORMAL);
  176. }
  177. else if (e2->status == -3) //用户流量用完
  178. {
  179. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  180. if (onlogin)
  181. {
  182. onlogin->SetWindowTextW(e2->msg);
  183. onlogin->EnableWindow(TRUE);
  184. onlogin->Invalidate();
  185. }
  186. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  187. ::ShellExecute(NULL, _T("open"), L"https://user.vipone.xyz/", NULL, NULL, SW_SHOWNORMAL);
  188. }
  189. else if (e2->status == 200)
  190. {
  191. /*if (m_network_tools)
  192. {
  193. m_network_tools->DonloadConfg();
  194. }*/
  195. ToMain();
  196. }
  197. }
  198. void CLoginDlg::OnDonloadFinish(EventArgs* e)
  199. {
  200. EventDoWNload* e2 = sobj_cast<EventDoWNload>(e);
  201. if (e2)
  202. {
  203. if (e2->status != 200)
  204. {
  205. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  206. if (onlogin)
  207. {
  208. onlogin->SetWindowTextW(e2->msg);
  209. onlogin->EnableWindow(TRUE);
  210. onlogin->Invalidate();
  211. }
  212. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  213. }
  214. else {
  215. ToMain();
  216. }
  217. }
  218. }