LoginDlg.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. using LitJson;
  2. using SC.XR.Unity;
  3. using ShadowStudio.Mgr;
  4. using Studio.Scripts.HttpMessage;
  5. using Studio.WebSocket.Message;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Text.RegularExpressions;
  10. using UnityEngine;
  11. using UnityEngine.SceneManagement;
  12. using UnityEngine.UI;
  13. using XRTool.UI;
  14. using XRTool.Util;
  15. using XRTool.WorldUI;
  16. namespace ShadowStudio.UI
  17. {
  18. [RequireComponent(typeof(WorldDlg))]
  19. /// <summary>
  20. /// 登录的窗口
  21. /// </summary>
  22. public class LoginDlg : UnitySingleton<LoginDlg>
  23. {
  24. private string session;
  25. private SCInputField userInputField;
  26. private SCInputField passwordInputField;
  27. private Button loginBtn;
  28. private Button setBtn;
  29. private Toggle remberToggle;
  30. private GameObject verifyObj;
  31. private SCInputField verifyInputField;
  32. private RawImage verifyTexture;
  33. private Button verifyTextureBtn;
  34. // public bool isLock;
  35. private Text userRemind;
  36. private Text passwordRemind;
  37. private Text vcodeRemind;
  38. private Button phoneNumLoginBtn;
  39. private Button SNLoginBtn;
  40. WorldDlg dlg;
  41. private void Start()
  42. {
  43. CommonMethod.IsReceive = false;
  44. dlg = GetComponent<WorldDlg>();
  45. userInputField = dlg.GetChild<SCInputField>("UIRoot/UserInputField");
  46. //dlg.GetBreadthChild<SCInputField>("UserInputField")
  47. passwordInputField = dlg.GetChild<SCInputField>("UIRoot/PasswordInputField");
  48. loginBtn = dlg.GetChild<Button>("FullUIRoot/LoginBtn");
  49. setBtn = dlg.GetChild<Button>("UIRoot/SetBtn");
  50. remberToggle = dlg.GetChild<Toggle>("UIRoot/RemberToggle_CheckBox");
  51. remberToggle.isOn = LoginProxy.Instance.IsRemberUserAndPass; ;
  52. remberToggle.onValueChanged.AddListener(ClickOnToggle);
  53. verifyObj = dlg.GetChild<Transform>("UIRoot/VerifyObj").gameObject;
  54. verifyInputField = dlg.GetChild<SCInputField>("UIRoot/VerifyObj/VerifyInputField");
  55. verifyTexture = dlg.GetChild<RawImage>("UIRoot/VerifyObj/VerifyTexture");
  56. verifyTextureBtn = dlg.GetBreadthChild<Button>("VerifyTextureBtn");
  57. verifyTextureBtn.onClick.AddListener(OnClickChangeTex);
  58. if (LoginMgr.Instance.UserInfo != null && LoginProxy.Instance.IsRemberUserAndPass && !string.IsNullOrEmpty(LoginMgr.Instance.UserInfo.UserID) && LoginMgr.Instance.UserInfo.UserID != "null")
  59. {
  60. userInputField.text = LoginMgr.Instance.UserInfo.UserID;
  61. passwordInputField.text = LoginMgr.Instance.UserInfo.Password;
  62. }
  63. else
  64. {
  65. userInputField.text = "";
  66. passwordInputField.text = "";
  67. }
  68. loginBtn.onClick.AddListener(OnClickLogin);
  69. setBtn.onClick.AddListener(OnClickSet);
  70. userInputField.onEndEdit.AddListener(InputUserEnd);
  71. userInputField.onValueChanged.AddListener(UserValueChanged);
  72. passwordInputField.onEndEdit.AddListener(InputPassEnd);
  73. passwordInputField.onValueChanged.AddListener(PassValueChanged);
  74. verifyInputField.onEndEdit.AddListener(InputVerifyEnd);
  75. verifyInputField.onValueChanged.AddListener(VerifyValueChanged);
  76. userRemind = dlg.GetChild<Text>("UIRoot/ErrorRemind/UserRemind");
  77. passwordRemind = dlg.GetChild<Text>("UIRoot/ErrorRemind/PasswordRemind");
  78. vcodeRemind = dlg.GetChild<Text>("UIRoot/VerifyObj/VcodeRemind");
  79. phoneNumLoginBtn = dlg.GetChild<Button>("UIRoot/PhoneNumLoginBtn");
  80. SNLoginBtn = dlg.GetChild<Button>("UIRoot/SNLoginBtn");
  81. phoneNumLoginBtn.onClick.AddListener(OnClickPhoneLogin);
  82. SNLoginBtn.onClick.AddListener(OnClickSNLogin);
  83. Debug.Log("startOnInit。。。");
  84. WSHandler.User.OnInit -= onInit;
  85. WSHandler.User.OnInit += onInit;
  86. if(CommonMethod.isZiDong)
  87. Invoke("loginzidong",1f);
  88. //GameClient.Instance.Login(SystemSettingMgr.Instance.settings.Ip, int.Parse(SystemSettingMgr.Instance.settings.Port));
  89. LoginProxy.Instance.AccountLoginAction += AccountLoginHandler;
  90. LoginProxy.Instance.SNLoginAction += SNLoginHandler;
  91. LoginProxy.Instance.LoginErrorAction += LoginErrorHandler;
  92. LoginProxy.Instance.CaptchaCodeAction += CaptchaCodeHandler;
  93. }
  94. void loginzidong()
  95. {
  96. //NetWorkHeaders.Login("15821993590","123qweqwe", LoginOk, LoginFail);
  97. LoginProxy.Instance.RequestAccountPasswordLogin("15821993590", "123qweqwe");
  98. }
  99. public void clearUserF()
  100. {
  101. userInputField.text = "";
  102. }
  103. public void clearPassWord()
  104. {
  105. passwordInputField.text = "";
  106. }
  107. private void OnClickChangeTex()
  108. {
  109. LoginProxy.Instance.RequestCaptchaVerificationCode();
  110. }
  111. private void UserValueChanged(string user)//实时检测输入值的变化
  112. {
  113. userRemind.gameObject.SetActive(false);
  114. }
  115. private void InputUserEnd(string user)
  116. {
  117. if (user == "")
  118. {
  119. userRemind.gameObject.SetActive(true);
  120. userRemind.text = LanguageMgr.Instance.GetMessage("1011").Message;
  121. }
  122. //else
  123. //{
  124. // //Regex regEmail = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
  125. // Regex regNum = new Regex(@"^\d{11}$");
  126. // bool ismatchNum = regNum.IsMatch(user);
  127. // if (!ismatchNum)
  128. // {
  129. // userRemind.gameObject.SetActive(true);
  130. // userRemind.text = LanguageMgr.Instance.GetMessage("1012").Message;
  131. // }
  132. //}
  133. }
  134. private void PassValueChanged(string password)
  135. {
  136. passwordRemind.gameObject.SetActive(false);
  137. }
  138. private void InputPassEnd(string password)
  139. {
  140. if (password == "")
  141. {
  142. passwordRemind.gameObject.SetActive(true);
  143. passwordRemind.text = LanguageMgr.Instance.GetMessage("1013").Message;
  144. }
  145. else
  146. {
  147. if (password.Contains(" "))
  148. {
  149. passwordRemind.gameObject.SetActive(true);
  150. passwordRemind.text = LanguageMgr.Instance.GetMessage("1014").Message;
  151. }
  152. }
  153. }
  154. private void VerifyValueChanged(string verifyNum)
  155. {
  156. vcodeRemind.gameObject.SetActive(false);
  157. }
  158. private void InputVerifyEnd(string verifyNum)
  159. {
  160. if (verifyNum == "")
  161. {
  162. vcodeRemind.gameObject.SetActive(true);
  163. vcodeRemind.text = LanguageMgr.Instance.GetMessage("1015").Message;
  164. }
  165. }
  166. private void ClickOnToggle(bool ison)
  167. {
  168. LoginProxy.Instance.RemberUserAndPass(ison);
  169. }
  170. private void OnClickLogin()
  171. {
  172. // userInputField.text = "HBKC217147";
  173. //passwordInputField.text = "HBKC217147";
  174. userInputField.text = "ycst0008";
  175. passwordInputField.text = "yc123456";
  176. if (userInputField.text == "" || passwordInputField.text == "")
  177. {
  178. if (userInputField.text == "")
  179. {
  180. userRemind.gameObject.SetActive(true);
  181. userRemind.text = LanguageMgr.Instance.GetMessage("1011").Message;
  182. }
  183. else if (passwordInputField.text == "")
  184. {
  185. passwordRemind.gameObject.SetActive(true);
  186. passwordRemind.text = LanguageMgr.Instance.GetMessage("1013").Message;
  187. }
  188. }
  189. //else if (userRemind.gameObject.activeSelf == true || passwordRemind.gameObject.activeSelf == true)
  190. //{
  191. // return;
  192. //}
  193. else
  194. {
  195. if (!verifyObj.activeSelf)
  196. {
  197. loginBtn.enabled = false;
  198. Invoke("ReLoginBtn", 1f);
  199. LoginProxy.Instance.RequestAccountPasswordLogin(userInputField.text, passwordInputField.text);
  200. }
  201. else
  202. {
  203. if (verifyInputField.text != "")
  204. {
  205. loginBtn.enabled = false;
  206. Invoke("ReLoginBtn", 1f);
  207. LoginProxy.Instance.RequestAccountPasswordLogin(userInputField.text, passwordInputField.text, verifyInputField.text);
  208. }
  209. else
  210. {
  211. vcodeRemind.gameObject.SetActive(true);
  212. vcodeRemind.text = LanguageMgr.Instance.GetMessage("1015").Message;
  213. }
  214. }
  215. }
  216. }
  217. private void ReLoginBtn()
  218. {
  219. loginBtn.enabled = true;
  220. }
  221. public void ClickBreakLoginBtn()
  222. {
  223. //NetWorkHeaders.BreakNumLogin(LoginOk, LoginFail);
  224. //LoginProxy.Instance.RequestAdvanceAccount(userInputField.text, passwordInputField.text);
  225. if (!string.IsNullOrEmpty(CommonMethod.tempToken))
  226. {
  227. LoginProxy.Instance.RequestBreakLogin(CommonMethod.tempToken);
  228. CommonMethod.tempToken = "";
  229. }
  230. }
  231. private void onWebErrorClose(string data)
  232. {
  233. CommonMethod.ShowTextTusi();
  234. if (TuSi.Instance)
  235. {
  236. TuSi.Instance.ShowTextContent("大厅链接失败,请重新尝试!");
  237. }
  238. WSHandler._client.CloseWebSocket();
  239. }
  240. private void onInit(ConnectNotificationMessage message)
  241. {
  242. dlg.hideDlg(() => {
  243. CommonMethod.selfHomepeerId = message.data.peerId;
  244. if (UserInfoMgr.Instance.userConfig.Login_type == "3")
  245. {
  246. LoginViewMgr.Instance.LoadSence();
  247. }
  248. else
  249. {
  250. if (UserInfoMgr.Instance.userConfig.Nick_name == "" || UserInfoMgr.Instance.userConfig.Avatar == "")
  251. {
  252. LoginViewMgr.Instance.ShowView(LoginViewMgr.USERINITSETDLG);
  253. }
  254. else
  255. {
  256. LoginViewMgr.Instance.LoadSence();
  257. }
  258. }
  259. });
  260. }
  261. /// <summary>
  262. /// TODO 顶号登录 没处理
  263. /// </summary>
  264. void chongfudenglu()
  265. {
  266. ClickBreakLoginBtn();
  267. }
  268. private void GetSucess(Texture tex)
  269. {
  270. verifyTexture.texture = tex;
  271. }
  272. private void OnClickSet()
  273. {
  274. LoginViewMgr.Instance.ShowView(LoginViewMgr.SYSTEMSETDLG);
  275. }
  276. private void OnClickPhoneLogin()
  277. {
  278. LoginViewMgr.Instance.ShowView(LoginViewMgr.VERIFYLOGINDLG);
  279. }
  280. //TODO CaoTing 参考入口
  281. private void OnClickSNLogin()
  282. {
  283. SNLoginBtn.enabled = false;
  284. Invoke("ReSNLoginBtn", 1f);
  285. LoginProxy.Instance.RequestSNLogin();
  286. }
  287. private void ReSNLoginBtn()
  288. {
  289. SNLoginBtn.enabled = true;
  290. }
  291. protected override void OnDestroy()
  292. {
  293. base.OnDestroy();
  294. if (LoginProxy.Instance)
  295. {
  296. LoginProxy.Instance.AccountLoginAction -= AccountLoginHandler;
  297. LoginProxy.Instance.SNLoginAction -= SNLoginHandler;
  298. LoginProxy.Instance.LoginErrorAction -= LoginErrorHandler;
  299. LoginProxy.Instance.CaptchaCodeAction -= CaptchaCodeHandler;
  300. }
  301. WSHandler.User.OnInit -= onInit;
  302. }
  303. /// <summary>
  304. /// 图形验证码
  305. /// </summary>
  306. /// <param name="captchaID"></param>
  307. /// <param name="bs64"></param>
  308. private void CaptchaCodeHandler(string captchaID, string bs64)
  309. {
  310. verifyTexture.texture = UnityUtil.Base642Tex2d(bs64);
  311. }
  312. private void LoginErrorHandler(MessageType messageType, int code, string codeMessage)
  313. {
  314. if (messageType == MessageType.AccountLoginType)
  315. {
  316. switch (code.ToString())
  317. {
  318. case "6006"://-2 账号已登录
  319. CommonMethod.ShowLoginAbnormalPop();
  320. if (CommonMethod.isZiDong)
  321. Invoke("chongfudenglu", 2f);
  322. break;
  323. case "9002":
  324. CommonMethod.ShowTextTusi();
  325. TuSi.Instance.ShowTextContent("服务器异常,请稍后重试");
  326. if (LoginProxy.Instance.LoginNum > 5)
  327. {
  328. this.verifyObj.SetActive(true);
  329. LoginProxy.Instance.RequestCaptchaVerificationCode();
  330. }
  331. break;
  332. case "5010":
  333. passwordRemind.gameObject.SetActive(true);
  334. passwordRemind.text = "账号和密码不匹配";
  335. if (LoginProxy.Instance.LoginNum > 5)
  336. {
  337. this.verifyObj.SetActive(true);
  338. LoginProxy.Instance.RequestCaptchaVerificationCode();
  339. }
  340. break;
  341. case "5006"://验证码错误
  342. vcodeRemind.gameObject.SetActive(true);
  343. vcodeRemind.text = "验证码输入错误";
  344. this.verifyObj.SetActive(true);
  345. LoginProxy.Instance.RequestCaptchaVerificationCode();
  346. break;
  347. case "6004":// 需要验证码
  348. vcodeRemind.gameObject.SetActive(true);
  349. vcodeRemind.text = "请输入右侧验证码";
  350. this.verifyObj.SetActive(true);
  351. LoginProxy.Instance.RequestCaptchaVerificationCode();
  352. break;
  353. case "5070"://图形验证码值不正确
  354. vcodeRemind.gameObject.SetActive(true);
  355. vcodeRemind.text = "验证码输入错误";
  356. this.verifyObj.SetActive(true);
  357. LoginProxy.Instance.RequestCaptchaVerificationCode();
  358. break;
  359. default:
  360. CommonMethod.ShowTextTusi();
  361. TuSi.Instance.ShowTextContent(codeMessage);
  362. break;
  363. }
  364. }
  365. }
  366. private void SNLoginHandler()
  367. {
  368. dlg.hideDlg();
  369. }
  370. private void AccountLoginHandler()
  371. {
  372. verifyObj.SetActive(false);
  373. if (!LoginProxy.Instance.IsRemberUserAndPass)
  374. {
  375. userInputField.text = string.Empty;
  376. passwordInputField.text = string.Empty;
  377. }
  378. }
  379. }
  380. }