LoginDlg.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. m_is_reg = FALSE;
  13. }
  14. CLoginDlg::~CLoginDlg()
  15. {
  16. }
  17. int CLoginDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  18. {
  19. SetMsgHandled(FALSE);
  20. return 0;
  21. }
  22. BOOL CLoginDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
  23. {
  24. m_bLayoutInited = TRUE;
  25. Init();
  26. return 0;
  27. }
  28. void CLoginDlg::Init()
  29. {
  30. //if (m_network_tools == nullptr)
  31. //{
  32. // m_network_tools = new CManageNetWork();
  33. // //m_network_tools.Attach(new CManageNetWork());
  34. // m_network_tools->init();
  35. //}
  36. CManageNetWork::getSingletonPtr()->init();
  37. ServerListUrl list;
  38. list.id = 0;
  39. list.name = L"首选";
  40. list.url = "https://api.ruanjian.buzz";
  41. ServerListUrl list1;
  42. list1.id = 1;
  43. list1.name = L"备用1";
  44. list1.url = "https://api.ruanjian1.buzz";
  45. ServerListUrl list2;
  46. list2.id = 2;
  47. list2.name = L"备用2";
  48. list2.url = "https://ruanjian2.xyz";
  49. vctInfo.push_back(list);
  50. vctInfo.push_back(list1);
  51. vctInfo.push_back(list2);
  52. StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"nodeclass");
  53. if (tabtype)
  54. {
  55. for (auto i = 0; i < vctInfo.size(); i++)
  56. {
  57. tabtype->ItemCreateChildren(vctInfo[i].id, vctInfo[i].name, i == 0 ? true : false);
  58. }
  59. if (vctInfo.size() > 0)
  60. {
  61. CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[0].url.c_str());
  62. //Curl::getSingletonPtr()->SetUrl(vctInfo[0].url);
  63. }
  64. tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  65. Subscriber(&CLoginDlg::OnTabtypeControl, this));
  66. }
  67. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  68. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  69. if (m_edit_username) {
  70. m_edit_username->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetUsername()));
  71. m_edit_username->Invalidate();
  72. }
  73. if (m_edit_password)
  74. {
  75. m_edit_password->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetPassWord()));
  76. m_edit_password->Invalidate();
  77. }
  78. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  79. if (onlogin)
  80. {
  81. onlogin->SetWindowTextW(L"正在获取系统配置..");
  82. onlogin->EnableWindow(FALSE);
  83. onlogin->Invalidate();
  84. }
  85. CManageNetWork::getSingletonPtr()->GetSysConfig();
  86. /*CManageNetWork::getSingletonPtr()->DonloadConfg();*/
  87. }
  88. bool CLoginDlg::OnTabtypeControl(SOUI::EventArgs* pEvt)
  89. {
  90. SOUI::EventTabtypeControl* pTestControlEvent =
  91. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  92. CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  93. /*if (m_curl)
  94. {
  95. m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  96. }*/
  97. //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
  98. return true;
  99. }
  100. //TODO:消息映射
  101. void CLoginDlg::OnClose()
  102. {
  103. CSimpleWnd::DestroyWindow();
  104. }
  105. void CLoginDlg::OnMaximize()
  106. {
  107. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  108. }
  109. void CLoginDlg::OnRestore()
  110. {
  111. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  112. }
  113. void CLoginDlg::OnMinimize()
  114. {
  115. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  116. }
  117. void CLoginDlg::OnLogin()
  118. {
  119. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  120. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  121. if (m_edit_username && m_edit_password)
  122. {
  123. auto username = m_edit_username->GetWindowTextW();
  124. auto password = m_edit_password->GetWindowTextW();
  125. /*if (m_base_curl) {
  126. char data[256] = { 0 };
  127. HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
  128. SLOG_DEBUG(data);
  129. }*/
  130. if (m_is_reg == FALSE)
  131. {
  132. CManageNetWork::getSingletonPtr()->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  133. }
  134. else {
  135. CManageNetWork::getSingletonPtr()->Reg(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  136. }
  137. }
  138. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  139. if (onlogin)
  140. {
  141. auto text = m_is_reg == FALSE ? L"正在登录..." : L"正在注册...";
  142. onlogin->SetWindowTextW(text);
  143. onlogin->EnableWindow(FALSE);
  144. onlogin->Invalidate();
  145. }
  146. /**/
  147. }
  148. void CLoginDlg::ToMain()
  149. {
  150. CApp::getSingletonPtr()->SetOut(1);
  151. CSimpleWnd::DestroyWindow();
  152. }
  153. void CLoginDlg::OnUpdateLInkUI()
  154. {
  155. /*SLink* reglink = FindChildByName2<SLink>(L"reglink");
  156. if (reglink)
  157. {
  158. reglink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reg.c_str(),CP_UTF8));
  159. reglink->UpdateWindow();
  160. }*/
  161. SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
  162. if (resetlink)
  163. {
  164. resetlink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reset.c_str(), CP_UTF8));
  165. resetlink->UpdateWindow();
  166. }
  167. }
  168. void CLoginDlg::OnLoginFinish(EventArgs* e)
  169. {
  170. EventLogin* e2 = sobj_cast<EventLogin>(e);
  171. if (!e2)
  172. {
  173. return;
  174. }
  175. if (e2->status == 0)
  176. {
  177. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  178. if (onlogin)
  179. {
  180. onlogin->SetWindowTextW(e2->msg);
  181. onlogin->EnableWindow(TRUE);
  182. onlogin->Invalidate();
  183. }
  184. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  185. } else if (e2->status == -1)
  186. {
  187. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  188. if (onlogin)
  189. {
  190. onlogin->SetWindowTextW(e2->msg);
  191. onlogin->EnableWindow(TRUE);
  192. onlogin->Invalidate();
  193. }
  194. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  195. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
  196. }
  197. else if (e2->status == -2) //用户到期
  198. {
  199. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  200. if (onlogin)
  201. {
  202. onlogin->SetWindowTextW(e2->msg);
  203. onlogin->EnableWindow(TRUE);
  204. onlogin->Invalidate();
  205. }
  206. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  207. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
  208. }
  209. else if (e2->status == -3) //用户流量用完
  210. {
  211. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  212. if (onlogin)
  213. {
  214. onlogin->SetWindowTextW(e2->msg);
  215. onlogin->EnableWindow(TRUE);
  216. onlogin->Invalidate();
  217. }
  218. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  219. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetOnlineLink(), NULL, NULL, SW_SHOWNORMAL);
  220. }
  221. else if (e2->status == 200)
  222. {
  223. /*if (m_network_tools)
  224. {
  225. m_network_tools->DonloadConfg();
  226. }*/
  227. ToMain();
  228. }
  229. }
  230. void CLoginDlg::OnDonloadFinish(EventArgs* e)
  231. {
  232. EventDoWNload* e2 = sobj_cast<EventDoWNload>(e);
  233. if (e2)
  234. {
  235. if (e2->status != 200)
  236. {
  237. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  238. if (onlogin)
  239. {
  240. onlogin->SetWindowTextW(e2->msg);
  241. onlogin->EnableWindow(TRUE);
  242. onlogin->Invalidate();
  243. }
  244. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  245. }
  246. else {
  247. ToMain();
  248. }
  249. }
  250. }
  251. void CLoginDlg::OnSysConfig(EventArgs* e)
  252. {
  253. EventSysconfig* e2 = sobj_cast<EventSysconfig>(e);
  254. if (e2)
  255. {
  256. if (e2->status == 200)
  257. {
  258. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  259. if (onlogin)
  260. {
  261. onlogin->SetWindowTextW(L"获取配置成功,点击登录");
  262. onlogin->EnableWindow(TRUE);
  263. onlogin->Invalidate();
  264. }
  265. OnUpdateLInkUI();
  266. }
  267. else {
  268. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  269. }
  270. }
  271. }
  272. void CLoginDlg::OnReg()
  273. {
  274. if (m_is_reg == FALSE)
  275. {
  276. SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
  277. if (resetlink)
  278. {
  279. resetlink->SetAttribute(L"show", L"0");
  280. resetlink->Invalidate();
  281. }
  282. SLink* reglink = FindChildByName2<SLink>(L"reglink");
  283. if (reglink)
  284. {
  285. reglink->SetWindowTextW(L"切换登录界面");
  286. ///reglink->SetAttribute(L"show", L"0");
  287. reglink->Invalidate();
  288. }
  289. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  290. if (onlogin)
  291. {
  292. onlogin->SetWindowTextW(L"点击注册");
  293. onlogin->EnableWindow(TRUE);
  294. onlogin->Invalidate();
  295. }
  296. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  297. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  298. if (m_edit_username && m_edit_password)
  299. {
  300. /*auto username = m_edit_username->GetWindowTextW();
  301. auto password = m_edit_password->GetWindowTextW();*/
  302. m_edit_username->SetWindowTextW(L"");
  303. m_edit_password->SetWindowTextW(L"");
  304. }
  305. m_is_reg = TRUE;
  306. }
  307. else
  308. {
  309. SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
  310. if (resetlink)
  311. {
  312. resetlink->SetAttribute(L"show", L"1");
  313. resetlink->Invalidate();
  314. }
  315. SLink* reglink = FindChildByName2<SLink>(L"reglink");
  316. if (reglink)
  317. {
  318. reglink->SetWindowTextW(L"注册新用户");
  319. ///reglink->SetAttribute(L"show", L"0");
  320. reglink->Invalidate();
  321. }
  322. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  323. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  324. if (m_edit_username) {
  325. m_edit_username->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetUsername()));
  326. m_edit_username->Invalidate();
  327. }
  328. if (m_edit_password)
  329. {
  330. m_edit_password->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetPassWord()));
  331. m_edit_password->Invalidate();
  332. }
  333. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  334. if (onlogin)
  335. {
  336. onlogin->SetWindowTextW(L"点击登录");
  337. onlogin->EnableWindow(TRUE);
  338. onlogin->Invalidate();
  339. }
  340. m_is_reg = FALSE;
  341. }
  342. }