RegisterView.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System.Text.RegularExpressions;
  2. using ET;
  3. using UI.Login;
  4. using UnityEngine;
  5. using FairyGUI;
  6. namespace GFGGame
  7. {
  8. public class RegisterView : BaseWindow
  9. {
  10. private UI_RegisterUI _ui;
  11. public override void Dispose()
  12. {
  13. if (_ui != null)
  14. {
  15. _ui.Dispose();
  16. _ui = null;
  17. }
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. packageName = UI_RegisterUI.PACKAGE_NAME;
  24. _ui = UI_RegisterUI.Create();
  25. this.viewCom = _ui.target;
  26. this.viewCom.Center();
  27. this.modal = true;
  28. _ui.m_btnSubmit.onClick.Add(OnClickBtnSubmit);
  29. // _ui.m_richTextAgree.onClickLink.Add(OnClickRichTextAgreeLink);
  30. _ui.m_loaEventa.onClick.Add(() => { FullScreenTextController.Show("event:a"); });
  31. _ui.m_loaEventb.onClick.Add(() => { FullScreenTextController.Show("event:b"); });
  32. _ui.m_loaEventc.onClick.Add(() => { FullScreenTextController.Show("event:c"); });
  33. _ui.m_btnSendCode.onClick.Add(() =>
  34. {
  35. if (!Regex.IsMatch(_ui.m_inputPhone.text.Trim(), // 匹配所有中国大陆手机号(11 位,包括物联网和卫星电话)
  36. @"^(?:\+86)?1(?:3\d{3}|4[5-9]\d{2}|5[0-35-9]\d{2}|6[2567]\d{2}|7[0-8]\d{2}|8\d{3}|9[0-35-9]\d{2})\d{6}$"))
  37. {
  38. PromptController.Instance.ShowFloatTextPrompt("输入的手机号格式有误");
  39. return;
  40. }
  41. _ui.m_btnSendCode.enabled = false;
  42. //在此发送验证码
  43. SecurityHelper.GetMobileVerificationCode(_ui.m_inputPhone.text, SendCodeType.RegisterAccount)
  44. .Coroutine();
  45. float endTime = Time.time + 60;
  46. Timers.inst.Add(1, 0, timerCallback, endTime);
  47. timerCallback(endTime);
  48. });
  49. //输入限制
  50. _ui.m_inputAccount.restrict = "[0-9A-Za-z_]";
  51. _ui.m_inputPassword2.restrict = _ui.m_inputPassword.restrict = "[0-9A-Za-z_]";
  52. _ui.m_inputName.restrict = "[\u4e00-\u9fa5a-zA-Z]";
  53. _ui.m_inputIDNumber.restrict = "[a-zA-Z0-9]";
  54. }
  55. private void timerCallback(object param)
  56. {
  57. float endTime = (float)param;
  58. float remainTime = endTime - Time.time;
  59. if (remainTime <= 0)
  60. {
  61. _ui.m_btnSendCode.text = "发送验证码";
  62. _ui.m_btnSendCode.enabled = true;
  63. Timers.inst.Remove(timerCallback);
  64. }
  65. else
  66. {
  67. _ui.m_btnSendCode.text = (int)remainTime + "s后重发";
  68. }
  69. }
  70. protected override void OnShown()
  71. {
  72. base.OnShown();
  73. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowRegister);
  74. }
  75. protected override void OnHide()
  76. {
  77. base.OnHide();
  78. Timers.inst.Remove(timerCallback);
  79. }
  80. private void OnClickBtnSubmit()
  81. {
  82. CheckToSubmit();
  83. }
  84. private void CheckToSubmit()
  85. {
  86. string account = _ui.m_inputAccount.text.Trim();
  87. string password = _ui.m_inputPassword.text;
  88. string passwordSure = _ui.m_inputPassword2.text;
  89. string realName = _ui.m_inputName.text;
  90. string idNumberStr = _ui.m_inputIDNumber.text;
  91. string phoneNumber = _ui.m_inputPhone.text;
  92. string code = _ui.m_inputCode.text;
  93. if (string.IsNullOrEmpty(account))
  94. {
  95. PromptController.Instance.ShowFloatTextPrompt("请输入账号");
  96. return;
  97. }
  98. if (account.Length < 8) //最长输入在UI编辑器中做了限制
  99. {
  100. PromptController.Instance.ShowFloatTextPrompt("账号长度最少需要8位");
  101. return;
  102. }
  103. if (string.IsNullOrEmpty(password))
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("请输入密码");
  106. return;
  107. }
  108. if (password.Length < 8) //最长输入在UI编辑器中做了限制
  109. {
  110. PromptController.Instance.ShowFloatTextPrompt("密码长度最少需要8位");
  111. return;
  112. }
  113. if (passwordSure != password)
  114. {
  115. PromptController.Instance.ShowFloatTextPrompt("确认密码不一致");
  116. return;
  117. }
  118. GameController.CheckSpecialAccount(account);
  119. if (GameGlobal.antiAddiction)
  120. {
  121. if (realName.Length <= 0)
  122. {
  123. PromptController.Instance.ShowFloatTextPrompt("请输入真实姓名");
  124. return;
  125. }
  126. if (idNumberStr.Length <= 0)
  127. {
  128. PromptController.Instance.ShowFloatTextPrompt("请输入身份证号");
  129. return;
  130. }
  131. if (!_ui.m_btnAgree.selected)
  132. {
  133. PromptController.Instance.ShowFloatTextPrompt("请仔细阅读并同意服务协议、隐私政策、保护规则");
  134. return;
  135. }
  136. }
  137. LoginController.Register(account, password, realName, idNumberStr, code, phoneNumber).Coroutine();
  138. }
  139. }
  140. }