LoginDlg.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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://app.appwang1.top";
  41. ServerListUrl list1;
  42. list1.id = 1;
  43. list1.name = L"备用1";
  44. list1.url = "https://app.appwang2.net";
  45. ServerListUrl list2;
  46. list2.id = 2;
  47. list2.name = L"备用2";
  48. list2.url = "https://lanyun123.cc";
  49. vctInfo.push_back(list);
  50. vctInfo.push_back(list1);
  51. vctInfo.push_back(list2);
  52. vctInfoUrl.push_back(list);
  53. vctInfoUrl.push_back(list2);
  54. vctInfoUrl.push_back(list2);
  55. CManageNetWork::getSingletonPtr()->SetUrlList(vctInfo);
  56. //StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"nodeclass");
  57. //if (tabtype)
  58. //{
  59. // for (auto i = 0; i < vctInfo.size(); i++)
  60. // {
  61. // tabtype->ItemCreateChildren(vctInfo[i].id, vctInfo[i].name, i == 0 ? true : false);
  62. // }
  63. // if (vctInfo.size() > 0)
  64. // {
  65. // CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[0].url.c_str());
  66. //
  67. // //Curl::getSingletonPtr()->SetUrl(vctInfo[0].url);
  68. // }
  69. // tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  70. // Subscriber(&CLoginDlg::OnTabtypeControl, this));
  71. //}
  72. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  73. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  74. if (m_edit_username) {
  75. m_edit_username->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetUsername()));
  76. m_edit_username->Invalidate();
  77. }
  78. if (m_edit_password)
  79. {
  80. m_edit_password->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetPassWord()));
  81. m_edit_password->Invalidate();
  82. }
  83. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  84. if (regstatus)
  85. {
  86. //auto text = m_is_reg == FALSE ? L"正在登录..." : L"正在注册...";
  87. regstatus->SetWindowTextW(L"正在获取系统配置..");
  88. ///reglink->SetAttribute(L"show", L"0");
  89. regstatus->Invalidate();
  90. }
  91. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  92. if (onlogin)
  93. {
  94. //onlogin->SetWindowTextW(L"正在获取系统配置..");
  95. onlogin->EnableWindow(FALSE);
  96. onlogin->Invalidate();
  97. }
  98. //SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  99. //if (onlogin)
  100. //{
  101. // //onlogin->SetWindowTextW(L"正在获取系统配置..");
  102. // onlogin->EnableWindow(FALSE);
  103. // onlogin->Invalidate();
  104. //}
  105. CManageNetWork::getSingletonPtr()->GetSysConfig();
  106. /*CManageNetWork::getSingletonPtr()->DonloadConfg();*/
  107. }
  108. bool CLoginDlg::OnTabtypeControl(SOUI::EventArgs* pEvt)
  109. {
  110. SOUI::EventTabtypeControl* pTestControlEvent =
  111. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  112. CManageNetWork::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  113. /*if (m_curl)
  114. {
  115. m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  116. }*/
  117. //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
  118. return true;
  119. }
  120. //TODO:消息映射
  121. void CLoginDlg::OnClose()
  122. {
  123. CSimpleWnd::DestroyWindow();
  124. }
  125. void CLoginDlg::OnMaximize()
  126. {
  127. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  128. }
  129. void CLoginDlg::OnRestore()
  130. {
  131. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  132. }
  133. void CLoginDlg::OnMinimize()
  134. {
  135. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  136. }
  137. void CLoginDlg::OnLogin()
  138. {
  139. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  140. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  141. if (m_edit_username && m_edit_password)
  142. {
  143. auto username = m_edit_username->GetWindowTextW();
  144. auto password = m_edit_password->GetWindowTextW();
  145. if (username.IsEmpty() || password.IsEmpty())
  146. {
  147. SMessageBox(m_hWnd, L"账号或者密码不能为空", L"提示", 0);
  148. return;
  149. }
  150. /*if (m_base_curl) {
  151. char data[256] = { 0 };
  152. HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
  153. SLOG_DEBUG(data);
  154. }*/
  155. if (m_is_reg == FALSE)
  156. {
  157. CManageNetWork::getSingletonPtr()->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  158. }
  159. else {
  160. CManageNetWork::getSingletonPtr()->Reg(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  161. }
  162. }
  163. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  164. if (regstatus)
  165. {
  166. auto text = m_is_reg == FALSE ? L"正在登录..." : L"正在注册...";
  167. regstatus->SetWindowTextW(text);
  168. ///reglink->SetAttribute(L"show", L"0");
  169. regstatus->Invalidate();
  170. }
  171. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  172. if (onlogin)
  173. {
  174. //onlogin->SetWindowTextW(text);
  175. onlogin->EnableWindow(FALSE);
  176. onlogin->Invalidate();
  177. }
  178. /**/
  179. }
  180. void CLoginDlg::ToMain()
  181. {
  182. CApp::getSingletonPtr()->SetOut(1);
  183. CSimpleWnd::DestroyWindow();
  184. }
  185. void CLoginDlg::OnUpdateLInkUI()
  186. {
  187. SLink* reglink = FindChildByName2<SLink>(L"reglink");
  188. if (reglink)
  189. {
  190. reglink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reg.c_str(),CP_UTF8));
  191. reglink->UpdateWindow();
  192. }
  193. SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
  194. if (resetlink)
  195. {
  196. resetlink->SetAttribute(L"href", S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reset.c_str(), CP_UTF8));
  197. resetlink->UpdateWindow();
  198. }
  199. }
  200. void CLoginDlg::OnLoginFinish(EventArgs* e)
  201. {
  202. EventLogin* e2 = sobj_cast<EventLogin>(e);
  203. if (!e2)
  204. {
  205. return;
  206. }
  207. if (e2->status == 0)
  208. {
  209. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  210. if (regstatus)
  211. {
  212. regstatus->SetWindowTextW(e2->msg);
  213. ///reglink->SetAttribute(L"show", L"0");
  214. regstatus->Invalidate();
  215. }
  216. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  217. if (onlogin)
  218. {
  219. //onlogin->SetWindowTextW(e2->msg);
  220. onlogin->EnableWindow(TRUE);
  221. onlogin->Invalidate();
  222. }
  223. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  224. } else if (e2->status == -1)
  225. {
  226. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  227. if (regstatus)
  228. {
  229. regstatus->SetWindowTextW(e2->msg);
  230. ///reglink->SetAttribute(L"show", L"0");
  231. regstatus->Invalidate();
  232. }
  233. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  234. if (onlogin)
  235. {
  236. //onlogin->SetWindowTextW(e2->msg);
  237. onlogin->EnableWindow(TRUE);
  238. onlogin->Invalidate();
  239. }
  240. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  241. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
  242. }
  243. else if (e2->status == -2) //用户到期
  244. {
  245. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  246. if (regstatus)
  247. {
  248. regstatus->SetWindowTextW(e2->msg);
  249. ///reglink->SetAttribute(L"show", L"0");
  250. regstatus->Invalidate();
  251. }
  252. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  253. if (onlogin)
  254. {
  255. //onlogin->SetWindowTextW(e2->msg);
  256. onlogin->EnableWindow(TRUE);
  257. onlogin->Invalidate();
  258. }
  259. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  260. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetBuyLink(), NULL, NULL, SW_SHOWNORMAL);
  261. }
  262. else if (e2->status == -3) //用户流量用完
  263. {
  264. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  265. if (regstatus)
  266. {
  267. regstatus->SetWindowTextW(e2->msg);
  268. ///reglink->SetAttribute(L"show", L"0");
  269. regstatus->Invalidate();
  270. }
  271. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  272. if (onlogin)
  273. {
  274. //onlogin->SetWindowTextW(e2->msg);
  275. onlogin->EnableWindow(TRUE);
  276. onlogin->Invalidate();
  277. }
  278. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  279. ::ShellExecute(NULL, _T("open"), CApp::getSingletonPtr()->GetSysconfig()->GetOnlineLink(), NULL, NULL, SW_SHOWNORMAL);
  280. }
  281. else if (e2->status == 200)
  282. {
  283. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  284. if (regstatus)
  285. {
  286. regstatus->SetWindowTextW(L"加载配置中...");
  287. ///reglink->SetAttribute(L"show", L"0");
  288. regstatus->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. //CManageNetWork::getSingletonPtr()->DonloadConfg();
  298. ToMain();
  299. }
  300. }
  301. void CLoginDlg::OnDonloadFinish(EventArgs* e)
  302. {
  303. EventDoWNload* e2 = sobj_cast<EventDoWNload>(e);
  304. if (e2)
  305. {
  306. if (e2->status != 200)
  307. {
  308. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  309. if (regstatus)
  310. {
  311. regstatus->SetWindowTextW(e2->msg);
  312. ///reglink->SetAttribute(L"show", L"0");
  313. regstatus->Invalidate();
  314. }
  315. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  316. if (onlogin)
  317. {
  318. onlogin->EnableWindow(TRUE);
  319. onlogin->Invalidate();
  320. }
  321. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  322. }
  323. else {
  324. ToMain();
  325. }
  326. }
  327. }
  328. void CLoginDlg::OnSysConfig(EventArgs* e)
  329. {
  330. EventSysconfig* e2 = sobj_cast<EventSysconfig>(e);
  331. if (e2)
  332. {
  333. if (e2->status == 200)
  334. {
  335. SStatic* regstatus = FindChildByName2<SStatic>(L"regstatus");
  336. if (regstatus)
  337. {
  338. regstatus->SetWindowTextW(L"获取配置成功,点击登录");
  339. ///reglink->SetAttribute(L"show", L"0");
  340. regstatus->Invalidate();
  341. }
  342. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  343. if (onlogin)
  344. {
  345. //onlogin->SetWindowTextW(L"获取配置成功,点击登录");
  346. onlogin->EnableWindow(TRUE);
  347. onlogin->Invalidate();
  348. }
  349. OnUpdateLInkUI();
  350. }
  351. else {
  352. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  353. }
  354. }
  355. }
  356. void CLoginDlg::OnReg()
  357. {
  358. if (CApp::getSingletonPtr()->GetSysconfig() != nullptr)
  359. {
  360. if (!CApp::getSingletonPtr()->GetSysconfig()->user_reg.empty())
  361. {
  362. ::ShellExecute(NULL, _T("open"),S_CA2W(CApp::getSingletonPtr()->GetSysconfig()->user_reg.c_str()), NULL, NULL, SW_SHOWNORMAL);
  363. }
  364. }
  365. //if (m_is_reg == FALSE)
  366. //{
  367. // SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
  368. // if (resetlink)
  369. // {
  370. // resetlink->SetAttribute(L"show", L"0");
  371. // resetlink->Invalidate();
  372. // }
  373. // SLink* reglink = FindChildByName2<SLink>(L"reglink");
  374. // if (reglink)
  375. // {
  376. // reglink->SetWindowTextW(L"切换登录界面");
  377. // ///reglink->SetAttribute(L"show", L"0");
  378. // reglink->Invalidate();
  379. // }
  380. // SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  381. // if (onlogin)
  382. // {
  383. // onlogin->SetWindowTextW(L"点击注册");
  384. // onlogin->EnableWindow(TRUE);
  385. // onlogin->Invalidate();
  386. // }
  387. // SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  388. // SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  389. // if (m_edit_username && m_edit_password)
  390. // {
  391. // /*auto username = m_edit_username->GetWindowTextW();
  392. // auto password = m_edit_password->GetWindowTextW();*/
  393. // m_edit_username->SetWindowTextW(L"");
  394. // m_edit_password->SetWindowTextW(L"");
  395. // }
  396. // m_is_reg = TRUE;
  397. //}
  398. //else
  399. //{
  400. // SLink* resetlink = FindChildByName2<SLink>(L"resetlink");
  401. // if (resetlink)
  402. // {
  403. // resetlink->SetAttribute(L"show", L"1");
  404. // resetlink->Invalidate();
  405. // }
  406. // SLink* reglink = FindChildByName2<SLink>(L"reglink");
  407. // if (reglink)
  408. // {
  409. // reglink->SetWindowTextW(L"注册新用户");
  410. // ///reglink->SetAttribute(L"show", L"0");
  411. // reglink->Invalidate();
  412. // }
  413. // SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  414. // SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  415. // if (m_edit_username) {
  416. // m_edit_username->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetUsername()));
  417. // m_edit_username->Invalidate();
  418. // }
  419. // if (m_edit_password)
  420. // {
  421. // m_edit_password->SetWindowTextW(S_CA2W(CManageNetWork::getSingletonPtr()->GetPassWord()));
  422. // m_edit_password->Invalidate();
  423. // }
  424. // SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  425. // if (onlogin)
  426. // {
  427. // onlogin->SetWindowTextW(L"点击登录");
  428. // onlogin->EnableWindow(TRUE);
  429. // onlogin->Invalidate();
  430. // }
  431. // m_is_reg = FALSE;
  432. //}
  433. }