LoginDlg.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  78. if (onlogin)
  79. {
  80. onlogin->SetWindowTextW(L"正在获取系统配置..");
  81. onlogin->EnableWindow(FALSE);
  82. onlogin->Invalidate();
  83. }
  84. CManageNetWork::getSingletonPtr()->GetSysConfig();
  85. /*CManageNetWork::getSingletonPtr()->DonloadConfg();*/
  86. }
  87. bool CLoginDlg::OnTabtypeControl(SOUI::EventArgs* pEvt)
  88. {
  89. SOUI::EventTabtypeControl* pTestControlEvent =
  90. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  91. CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  92. /*if (m_curl)
  93. {
  94. m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  95. }*/
  96. //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
  97. return true;
  98. }
  99. //TODO:消息映射
  100. void CLoginDlg::OnClose()
  101. {
  102. CSimpleWnd::DestroyWindow();
  103. }
  104. void CLoginDlg::OnMaximize()
  105. {
  106. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  107. }
  108. void CLoginDlg::OnRestore()
  109. {
  110. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  111. }
  112. void CLoginDlg::OnMinimize()
  113. {
  114. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  115. }
  116. void CLoginDlg::OnLogin()
  117. {
  118. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  119. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  120. if (m_edit_username && m_edit_password)
  121. {
  122. auto username = m_edit_username->GetWindowTextW();
  123. auto password = m_edit_password->GetWindowTextW();
  124. /*if (m_base_curl) {
  125. char data[256] = { 0 };
  126. HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
  127. SLOG_DEBUG(data);
  128. }*/
  129. CManageNetWork::getSingletonPtr()->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  130. }
  131. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  132. if (onlogin)
  133. {
  134. onlogin->SetWindowTextW(L"正在登录...");
  135. onlogin->EnableWindow(FALSE);
  136. onlogin->Invalidate();
  137. }
  138. /**/
  139. }
  140. void CLoginDlg::ToMain()
  141. {
  142. CApp::getSingletonPtr()->SetOut(1);
  143. CSimpleWnd::DestroyWindow();
  144. }
  145. void CLoginDlg::OnUpdateLInkUI()
  146. {
  147. SLink* reglink = FindChildByName2<SLink>(L"reglink");
  148. if (reglink)
  149. {
  150. reglink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reg.c_str(),CP_UTF8));
  151. reglink->UpdateWindow();
  152. }
  153. SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
  154. if (resetlink)
  155. {
  156. resetlink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reg.c_str(), CP_UTF8));
  157. resetlink->UpdateWindow();
  158. }
  159. }
  160. void CLoginDlg::OnLoginFinish(EventArgs* e)
  161. {
  162. EventLogin* e2 = sobj_cast<EventLogin>(e);
  163. if (!e2)
  164. {
  165. return;
  166. }
  167. if (e2->status == 0)
  168. {
  169. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  170. if (onlogin)
  171. {
  172. onlogin->SetWindowTextW(e2->msg);
  173. onlogin->EnableWindow(TRUE);
  174. onlogin->Invalidate();
  175. }
  176. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  177. } else if (e2->status == -1)
  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"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
  188. }
  189. else if (e2->status == -2) //用户到期
  190. {
  191. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  192. if (onlogin)
  193. {
  194. onlogin->SetWindowTextW(e2->msg);
  195. onlogin->EnableWindow(TRUE);
  196. onlogin->Invalidate();
  197. }
  198. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  199. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
  200. }
  201. else if (e2->status == -3) //用户流量用完
  202. {
  203. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  204. if (onlogin)
  205. {
  206. onlogin->SetWindowTextW(e2->msg);
  207. onlogin->EnableWindow(TRUE);
  208. onlogin->Invalidate();
  209. }
  210. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  211. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetOnlineLink(), NULL, NULL, SW_SHOWNORMAL);
  212. }
  213. else if (e2->status == 200)
  214. {
  215. /*if (m_network_tools)
  216. {
  217. m_network_tools->DonloadConfg();
  218. }*/
  219. ToMain();
  220. }
  221. }
  222. void CLoginDlg::OnDonloadFinish(EventArgs* e)
  223. {
  224. EventDoWNload* e2 = sobj_cast<EventDoWNload>(e);
  225. if (e2)
  226. {
  227. if (e2->status != 200)
  228. {
  229. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  230. if (onlogin)
  231. {
  232. onlogin->SetWindowTextW(e2->msg);
  233. onlogin->EnableWindow(TRUE);
  234. onlogin->Invalidate();
  235. }
  236. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  237. }
  238. else {
  239. ToMain();
  240. }
  241. }
  242. }
  243. void CLoginDlg::OnSysConfig(EventArgs* e)
  244. {
  245. EventSysconfig* e2 = sobj_cast<EventSysconfig>(e);
  246. if (e2)
  247. {
  248. if (e2->status == 200)
  249. {
  250. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  251. if (onlogin)
  252. {
  253. onlogin->SetWindowTextW(L"获取配置成功,点击登录");
  254. onlogin->EnableWindow(TRUE);
  255. onlogin->Invalidate();
  256. }
  257. OnUpdateLInkUI();
  258. }
  259. else {
  260. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  261. }
  262. }
  263. }