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