RegisterView.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using UnityEngine.SceneManagement;
  7. using UnityEngine.Networking;
  8. using System.Text.RegularExpressions;
  9. using DG.Tweening;
  10. using Newtonsoft.Json;
  11. using JCUnityLib;
  12. using JCUnityLib.UI;
  13. using Newtonsoft.Json.Linq;
  14. /* 注册界面 */
  15. public class RegisterView : MonoBehaviour
  16. {
  17. [SerializeField] GameObject registerContainer;
  18. [SerializeField] GameObject improveContainer;
  19. [SerializeField] GameObject registerInUser;
  20. [SerializeField] GameObject registerInPWD1;
  21. [SerializeField] GameObject registerInPWD2;
  22. [SerializeField] GameObject registerInEmail;
  23. [SerializeField] GameObject registerInPhone;
  24. [SerializeField] GameObject registerInCaptcha;
  25. [SerializeField] GameObject registerInNickname;
  26. [SerializeField] GameObject registerInGender;
  27. [SerializeField] GameObject registerInBirthday;
  28. [SerializeField] GameObject registerInLocation;
  29. [SerializeField] GameObject btnNext;
  30. [SerializeField] GameObject btnSave;
  31. [SerializeField] GameObject lineTip;
  32. [SerializeField] GameObject agreenment;
  33. [SerializeField] GameObject passwordTip;
  34. [SerializeField] Button SendBtn;
  35. [SerializeField] Text SendBtnText;
  36. InputField _inputRelateAccount;
  37. string sendCodeAccount;
  38. InputField _inputValidateCode;
  39. //状态记录
  40. public int captcha_Register = -222222222;
  41. public string captcha_Register_str = "";
  42. void OnEnable()
  43. {
  44. InitPage();
  45. //弹出协议,不同意则退出注册
  46. AgreementPopup agreementPopup = transform.parent.Find("AgreementPopup").GetComponent<AgreementPopup>();
  47. agreementPopup.onDisagree = () => {
  48. agreementPopup.onDisagree = null;
  49. GameObject.FindObjectOfType<LoginMgr>().showLoginView();
  50. };
  51. agreementPopup.gameObject.SetActive(true);
  52. }
  53. void Start()
  54. {
  55. InitInputLimit();
  56. //把账户视为手机号或者邮箱
  57. _inputRelateAccount = GetGameObjectInputField(registerInUser);
  58. _inputValidateCode = GetGameObjectInputField(registerInPhone);
  59. if (CommonConfig.serverIndex == 0)
  60. {
  61. //国内使用手机注册
  62. SetLoginValidateType(LoginValidateType.Phone);
  63. }
  64. else
  65. {
  66. //国外使用邮箱注册
  67. SetLoginValidateType(LoginValidateType.Email);
  68. }
  69. SendBtnText.text = TextAutoLanguage2.GetTextByKey("common_send");
  70. }
  71. void InitInputLimit() {
  72. GameObject[] inputNodes = {registerInPWD1, registerInPWD2};
  73. foreach (var inputNode in inputNodes) {
  74. InputField inputField = GetInputField(inputNode);
  75. inputField.onValueChanged.AddListener(delegate(string text) {
  76. Match match = new Regex("[^A-Za-z0-9]").Match(text);
  77. if (match.Success)
  78. {
  79. inputField.text = text.Replace(match.Value, "");
  80. }
  81. //if (_LoginValidateType == LoginValidateType.Email)
  82. //{
  83. // Match matchEmail = new Regex("^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$").Match(text);
  84. // if (matchEmail.Success)
  85. // {
  86. // inputField.text = text.Replace(matchEmail.Value, "");
  87. // }
  88. //}
  89. //else {
  90. // Match match = new Regex("[^A-Za-z0-9]").Match(text);
  91. // if (match.Success)
  92. // {
  93. // inputField.text = text.Replace(match.Value, "");
  94. // }
  95. //}
  96. });
  97. }
  98. }
  99. void InitPage(bool isNext = false) {
  100. registerContainer.SetActive(!isNext);
  101. //registerInUser.SetActive(!isNext);
  102. //registerInPWD1.SetActive(!isNext);
  103. //registerInPWD2.SetActive(!isNext);
  104. //registerInPhone.SetActive(!isNext);
  105. //registerInCaptcha.SetActive(!isNext);
  106. btnNext.SetActive(!isNext);
  107. agreenment.SetActive(!isNext);
  108. //var btnNextTF = btnNext.transform as RectTransform;
  109. //var btnNextAP = btnNextTF.anchoredPosition;
  110. //btnNextAP.y = -540;
  111. //btnNextTF.anchoredPosition = btnNextAP;
  112. //registerInEmail.SetActive(!isNext && CommonConfig.serverIndex == 1);
  113. //registerInPhone.SetActive(!isNext && CommonConfig.serverIndex == 0);
  114. //if (CommonConfig.banBindRelateAccount)
  115. //{
  116. // registerInEmail.SetActive(false);
  117. // registerInPhone.SetActive(false);
  118. //}
  119. //lineTip.SetActive(registerInEmail.activeSelf && registerInPhone.activeSelf);
  120. //if (registerInEmail.activeSelf) btnNextAP.y -= 14;
  121. //if (registerInPhone.activeSelf) btnNextAP.y -= 14;
  122. improveContainer.SetActive(isNext);
  123. //registerInNickname.SetActive(isNext);
  124. //registerInGender.SetActive(isNext);
  125. //registerInBirthday.SetActive(isNext);
  126. //registerInLocation.SetActive(isNext);
  127. btnSave.SetActive(isNext);
  128. if (isNext) {
  129. GetLocation();
  130. } else {
  131. ChnageCaptcha();
  132. }
  133. }
  134. InputField GetInputField(GameObject inputNode) {
  135. return inputNode.transform.Find("InputField").GetComponent<InputField>();
  136. }
  137. InputField GetGameObjectInputField(GameObject inputNode)
  138. {
  139. return inputNode.transform.Find("GameObject/InputField").GetComponent<InputField>();
  140. }
  141. public void ChnageCaptcha() {
  142. StartCoroutine(CaptchaController.Instance.GetCaptcha(
  143. registerInCaptcha.transform.Find("GameObject/Mask/CodeImage").GetComponent<Image>(),
  144. (code) => { captcha_Register_str = code.ToString(); }
  145. ));
  146. //captcha_Register_str = CaptchaController.Instance.GetCaptchaV2(registerInCaptcha.transform.Find("GameObject/Mask/CodeImage").GetComponent<Image>());
  147. }
  148. string _bindingEmail = "";
  149. public void OnClick_BindEmail()
  150. {
  151. RelateValidateView relateValidateView =
  152. Instantiate(SceneResourceManager.Instance.GetPrefab("RelateValidateView"))
  153. .GetComponent<RelateValidateView>();
  154. CanvasUtils.PlusSortOrder(gameObject.GetComponentInParent<Canvas>().gameObject, relateValidateView.gameObject, 1);
  155. relateValidateView.InitForEmail2();
  156. relateValidateView.onValidateSuccess = (a, b, c) => {
  157. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-pass1"));
  158. relateValidateView.CloseView();
  159. GetInputField(registerInEmail).text = _bindingEmail = a;
  160. };
  161. }
  162. string _bindingPhone = "";
  163. //public void OnClick_BindPhone()
  164. //{
  165. // RelateValidateView relateValidateView =
  166. // Instantiate(SceneResourceManager.Instance.GetPrefab("RelateValidateView"))
  167. // .GetComponent<RelateValidateView>();
  168. // CanvasUtils.PlusSortOrder(gameObject.GetComponentInParent<Canvas>().gameObject, relateValidateView.gameObject, 1);
  169. // relateValidateView.InitForPhone2();
  170. // relateValidateView.onValidateSuccess = (a, b, c) => {
  171. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-pass1"));
  172. // relateValidateView.CloseView();
  173. // GetInputField(registerInPhone).text = _bindingPhone = a;
  174. // };
  175. //}
  176. public enum LoginValidateType { Email, Phone }
  177. private LoginValidateType _LoginValidateType = LoginValidateType.Email;
  178. public void SetLoginValidateType(LoginValidateType _loginValidateType)
  179. {
  180. _LoginValidateType = _loginValidateType;
  181. LanguageEnum languageEnum = TextAutoLanguage2.GetLanguage();
  182. if (_LoginValidateType == LoginValidateType.Email)
  183. {
  184. _inputRelateAccount.contentType = InputField.ContentType.EmailAddress;
  185. _inputRelateAccount.characterLimit = 32;
  186. registerInUser.transform.Find("Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("register_email2");
  187. _inputRelateAccount.transform.Find("Placeholder").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email1");
  188. //输入框文案
  189. registerInPhone.transform.Find("Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email001");
  190. //输入框提示
  191. Text _tempCodeText = _inputValidateCode.transform.Find("Placeholder").GetComponent<Text>();
  192. //_tempCodeText.fontSize = languageEnum == LanguageEnum.Chinese ? 24 : 20;
  193. _tempCodeText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email201"); //RelateValidateView-email2
  194. //发送按钮
  195. registerInPhone.transform.Find("GameObject/Send/Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("common_send"); //RelateValidateView-email3
  196. }
  197. else if (_LoginValidateType == LoginValidateType.Phone)
  198. {
  199. _inputRelateAccount.contentType = InputField.ContentType.IntegerNumber;
  200. _inputRelateAccount.characterLimit = 11;
  201. registerInUser.transform.Find("Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("register_phone2");
  202. _inputRelateAccount.transform.Find("Placeholder").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("RelateValidateView-phone1");
  203. //手机部分的验证码也保持和邮件的文案一样
  204. registerInPhone.transform.Find("Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email001");//("RelateValidateView-phone0");
  205. Text _tempCodeText = _inputValidateCode.transform.Find("Placeholder").GetComponent<Text>();
  206. //_tempCodeText.fontSize = languageEnum == LanguageEnum.Chinese ? 24 : 20;
  207. _tempCodeText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email201");//("RelateValidateView-phone2");
  208. registerInPhone.transform.Find("GameObject/Send/Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("common_send");//RelateValidateView-phone3
  209. }
  210. }
  211. [SerializeField] GameObject _prefabValidateJigsawView;
  212. static long _throttlerBtnSend_phone_reg = 0;
  213. long _throttlerBtnSend_reg
  214. {
  215. get
  216. {
  217. return _throttlerBtnSend_phone_reg;
  218. }
  219. set
  220. {
  221. _throttlerBtnSend_phone_reg = value;
  222. }
  223. }
  224. public void OnClick_SendCode() {
  225. if (_LoginValidateType == LoginValidateType.Email)
  226. {
  227. string email = _inputRelateAccount.text;
  228. sendCodeAccount = email;
  229. if (!ValidateHelper.IsEmail(email))
  230. {
  231. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a0"));
  232. return;
  233. }
  234. }
  235. else if (_LoginValidateType == LoginValidateType.Phone)
  236. {
  237. //记录一个发送code时候的号码,下一步时候判定一下是否同一个号码,不是的话提示重新发送,和检测一下合理性
  238. string phone = _inputRelateAccount.text;
  239. sendCodeAccount = phone;
  240. if (!ValidateHelper.IsMobilePhone(phone))
  241. {
  242. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a1"));
  243. return;
  244. }
  245. }
  246. //验证码再次发送需要间隔60秒
  247. long gapTime = TimeUtils.GetTimestamp() - _throttlerBtnSend_reg;
  248. long maxTime = 60 * 1000;
  249. if (gapTime < maxTime)
  250. {
  251. long second = (maxTime - gapTime) / 1000;
  252. if (second <= 0) second = 1;
  253. PopupMgr.ins.ShowTip(string.Format(TextAutoLanguage2.GetTextByKey("RelateValidateView-a2"), second));
  254. return;
  255. }
  256. //打开拼图验证
  257. GameObject gameObjectValidateJigsawView = Instantiate(_prefabValidateJigsawView);
  258. //CanvasUtils.PlusSortOrder(gameObject, gameObjectValidateJigsawView, 1);
  259. ValidateJigsawView validateJigsawView = gameObjectValidateJigsawView.GetComponent<ValidateJigsawView>();
  260. validateJigsawView.onComplete = RequestSendValidateCode;
  261. validateJigsawView.SetTextLabel(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_label"));
  262. validateJigsawView.SetTextTip(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_tip"));
  263. validateJigsawView.SetTextOK(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_ok"));
  264. }
  265. bool bSend = false;
  266. private void Update()
  267. {
  268. if (bSend)
  269. {
  270. //验证码再次发送需要间隔60秒
  271. if (SendBtn.IsInteractable()) SendBtn.interactable = false;
  272. long gapTime = TimeUtils.GetTimestamp() - _throttlerBtnSend_reg;
  273. long maxTime = 60 * 1000;
  274. long second = (maxTime - gapTime) / 1000;
  275. if (second <= 0) second = 0;
  276. SendBtnText.text = second + " S";
  277. if (second == 0)
  278. {
  279. bSend = false;
  280. SendBtnText.text = TextAutoLanguage2.GetTextByKey("common_send");
  281. }
  282. }
  283. else {
  284. //停止计时
  285. if (!SendBtn.IsInteractable()) SendBtn.interactable = true;
  286. }
  287. }
  288. void RequestSendValidateCode()
  289. {
  290. //限流时间点记录
  291. _throttlerBtnSend_reg = TimeUtils.GetTimestamp();
  292. bSend = true;
  293. //请求服务端接口
  294. if (_LoginValidateType == LoginValidateType.Email)
  295. {
  296. string email = _inputRelateAccount.text;
  297. StartCoroutine(EmailValidateController.Instance.SendEmailValidateCode(email, (res) => {
  298. if (res.code == 0) PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b0"));
  299. else PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b1"));
  300. }));
  301. }
  302. else if (_LoginValidateType == LoginValidateType.Phone)
  303. {
  304. string phone = _inputRelateAccount.text;
  305. StartCoroutine(PhoneValidateController.Instance.SendPhoneValidateCode(phone, (res) => {
  306. if (res.code == 0) PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b2"));
  307. else PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b3"));
  308. }));
  309. }
  310. }
  311. Throttler _throttlerBtnSubmit = new Throttler(3000);
  312. public void OnClick_BtnSubmit()
  313. {
  314. if (_LoginValidateType == LoginValidateType.Email)
  315. {
  316. string email = _inputRelateAccount.text;
  317. if (!ValidateHelper.IsEmail(email))
  318. {
  319. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a0"));
  320. return;
  321. }
  322. }
  323. else if (_LoginValidateType == LoginValidateType.Phone)
  324. {
  325. string phone = _inputRelateAccount.text;
  326. if (!ValidateHelper.IsMobilePhone(phone))
  327. {
  328. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a1"));
  329. return;
  330. }
  331. }
  332. string code = _inputValidateCode.text;
  333. if (code.Length != 6)
  334. {
  335. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a3"));
  336. return;
  337. }
  338. if (!_throttlerBtnSubmit.CanPass())
  339. {
  340. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  341. return;
  342. }
  343. RequestSubmit();
  344. }
  345. void RequestSubmit()
  346. {
  347. if (_LoginValidateType == LoginValidateType.Email)
  348. {
  349. string email = _inputRelateAccount.text;
  350. string code = _inputValidateCode.text;
  351. StartCoroutine(EmailValidateController.Instance.ValidateEmail(email, code, (res) => {
  352. if (res.code == 0)
  353. {
  354. JObject data = res.data as JObject;
  355. string arg0 = data.Value<string>("email");
  356. long arg1 = data.Value<long>("timestamp");
  357. string arg2 = data.Value<string>("sign");
  358. Debug.Log($"邮箱验证成功 {arg0} {arg1} {arg2}");
  359. _bindingEmail = arg0;
  360. RegisterNext();
  361. }
  362. else PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-c0"));
  363. }));
  364. }
  365. else if (_LoginValidateType == LoginValidateType.Phone)
  366. {
  367. string phone = _inputRelateAccount.text;
  368. string code = _inputValidateCode.text;
  369. StartCoroutine(PhoneValidateController.Instance.ValidatePhone(phone, code, (res) => {
  370. if (res.code == 0)
  371. {
  372. JObject data = res.data as JObject;
  373. string arg0 = data.Value<string>("phone");
  374. long arg1 = data.Value<long>("timestamp");
  375. string arg2 = data.Value<string>("sign");
  376. Debug.Log($"手机验证成功 {arg0} {arg1} {arg2}");
  377. _bindingPhone = arg0;
  378. RegisterNext();
  379. }
  380. else PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-c1"));
  381. }));
  382. }
  383. }
  384. private string usrRecord = "";
  385. private string pwdRecord = "";
  386. JCUnityLib.Throttler throttlerRegisterNext = new JCUnityLib.Throttler(2000);
  387. public void onDetectPassword() {
  388. InputField pwd1 = GetInputField(registerInPWD1);
  389. InputField pwd2 = GetInputField(registerInPWD2);
  390. passwordTip.SetActive(pwd1.text != pwd2.text);
  391. }
  392. void TestNav() {
  393. InputField user = GetGameObjectInputField(registerInUser);
  394. InputField pwd1 = GetInputField(registerInPWD1);
  395. usrRecord = user.text;
  396. pwdRecord = pwd1.text;
  397. InputField nickname = GetInputField(registerInNickname);
  398. if (_LoginValidateType == LoginValidateType.Email)
  399. {
  400. //邮箱裁剪一下
  401. string[] arry = usrRecord.Trim().Split("@");
  402. nickname.text = arry[0];
  403. }
  404. else
  405. {
  406. //手机直接设置电话号码
  407. nickname.text = usrRecord;
  408. }
  409. InitPage(true);
  410. LoginView.ins.FillLoginInput(usrRecord, pwdRecord);
  411. }
  412. public void RegisterNext()
  413. {
  414. //TestNav();
  415. //return;
  416. //检测是否绑定手机号和邮箱号,没有进行绑定。绑定后再调用此流程
  417. if (!CommonConfig.banBindRelateAccount)
  418. {
  419. if (string.IsNullOrEmpty(_bindingEmail) && string.IsNullOrEmpty(_bindingPhone))
  420. {
  421. OnClick_BtnSubmit();
  422. return;
  423. }
  424. }
  425. //这里变成手机号或者邮箱号了
  426. if (_LoginValidateType == LoginValidateType.Email)
  427. {
  428. if (!ValidateHelper.IsEmail(_inputRelateAccount.text))
  429. {
  430. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a0"));
  431. return;
  432. }
  433. }
  434. else if (_LoginValidateType == LoginValidateType.Phone)
  435. {
  436. if (!ValidateHelper.IsMobilePhone(_inputRelateAccount.text))
  437. {
  438. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a1"));
  439. return;
  440. }
  441. }
  442. //更换账户后请重新发送验证码
  443. if (sendCodeAccount != _inputRelateAccount.text)
  444. {
  445. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a11"));
  446. return;
  447. }
  448. //if (user.text.Length < 6) {
  449. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("账号长度至少6位"));
  450. // return;
  451. //}
  452. InputField pwd1 = GetInputField(registerInPWD1);
  453. if (pwd1.text.Length < 6) {
  454. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("密码长度至少6位"));
  455. return;
  456. }
  457. InputField pwd2 = GetInputField(registerInPWD2);
  458. if (pwd1.text != pwd2.text) {
  459. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("两次输入的密码不一致"));
  460. passwordTip.SetActive(true);
  461. return;
  462. }
  463. // if (!CommonConfig.banBindRelateAccount)
  464. // {
  465. // if (string.IsNullOrEmpty(_bindingEmail) && string.IsNullOrEmpty(_bindingPhone)) {
  466. // if (CommonConfig.serverIndex == 0) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("至少需要绑定邮箱号或者手机号"));
  467. // else PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("尚未绑定邮箱号"));
  468. // return;
  469. // }
  470. // }
  471. //if (registerInEmail.activeSelf && string.IsNullOrEmpty(_bindingEmail)) {
  472. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("尚未绑定邮箱号"));
  473. // return;
  474. //}
  475. //if (registerInPhone.activeSelf && string.IsNullOrEmpty(_bindingPhone)) {
  476. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("尚未绑定手机号"));
  477. // return;
  478. //}
  479. InputField captcha = GetGameObjectInputField(registerInCaptcha);
  480. if (!captcha.text.Equals(captcha_Register_str)) {
  481. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("验证码错误"));
  482. return;
  483. }
  484. if (!AgreenmentOption.ins.IsAgreementChecked()) {
  485. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
  486. return;
  487. }
  488. if (throttlerRegisterNext.CanPass() == false) {
  489. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  490. return;
  491. }
  492. usrRecord = _inputRelateAccount.text;
  493. pwdRecord = pwd1.text;
  494. if (CommonConfig.banBindRelateAccount)
  495. {
  496. StartCoroutine(LoginController.Instance.Register(
  497. usrRecord, pwdRecord, (res) => {
  498. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  499. if (res.code == 0) {
  500. //设置默认名字,为当前注册的账户信息
  501. InputField nickname = GetInputField(registerInNickname);
  502. if (_LoginValidateType == LoginValidateType.Email)
  503. {
  504. //邮箱裁剪一下
  505. //string[] arry = usrRecord.Trim().Split("@");
  506. //nickname.text = arry[0];
  507. nickname.text = usrRecord;
  508. }
  509. else {
  510. //手机直接设置电话号码
  511. nickname.text = usrRecord;
  512. }
  513. InitPage(true); //前往完善用户信息
  514. LoginView.ins.FillLoginInput(usrRecord, pwdRecord);
  515. }
  516. }
  517. ));
  518. return;
  519. }
  520. StartCoroutine(LoginController.Instance.Register2(
  521. usrRecord, pwdRecord, _bindingEmail, _bindingPhone, (res) => {
  522. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  523. if (res.code == 0) {
  524. //设置默认名字,为当前注册的账户信息
  525. InputField nickname = GetInputField(registerInNickname);
  526. if (_LoginValidateType == LoginValidateType.Email)
  527. {
  528. //邮箱裁剪一下
  529. //string[] arry = usrRecord.Trim().Split("@");
  530. nickname.text = usrRecord;
  531. }
  532. else
  533. {
  534. //手机直接设置电话号码
  535. nickname.text = usrRecord;
  536. }
  537. InitPage(true); //前往完善用户信息
  538. LoginView.ins.FillLoginInput(usrRecord, pwdRecord);
  539. }
  540. }
  541. ));
  542. }
  543. JCUnityLib.Throttler throttlerRegisterSave = new JCUnityLib.Throttler(2000);
  544. public void RegisterSave() {
  545. InputField nickname = GetInputField(registerInNickname);
  546. string text_nickname = nickname.text.Trim();
  547. if (text_nickname.Length == 0) {
  548. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请输入游戏昵称"));
  549. return;
  550. }
  551. int gender = 0;
  552. Transform toggleGroup = registerInGender.transform.Find("ToggleGroup");
  553. for (int i = 0; i < toggleGroup.childCount; i++) {
  554. if (toggleGroup.GetChild(i).GetComponent<Toggle>().isOn) {
  555. gender = i == 0 ? 1 : 2;
  556. break;
  557. }
  558. }
  559. InputField birthday = GetInputField(registerInBirthday);
  560. string text_birthday = birthday.text;
  561. if (text_birthday.Length != 10) {
  562. text_birthday = "2000-01-01";
  563. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写出生日期"));
  564. // return;
  565. }
  566. InputField location = GetInputField(registerInLocation);
  567. if (location.text.Length == 0) {
  568. countryCode = "";
  569. stateCode = "";
  570. cityCode = "";
  571. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写所在地区"));
  572. // return;
  573. }
  574. if (!AgreenmentOption.ins.IsAgreementChecked()) {
  575. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
  576. return;
  577. }
  578. if (throttlerRegisterSave.CanPass() == false) {
  579. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  580. return;
  581. }
  582. StartCoroutine(LoginController.Instance.CompleteUserInfo(
  583. usrRecord, pwdRecord, text_nickname, gender, text_birthday,
  584. countryCode, stateCode, cityCode
  585. ,(res) => {
  586. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  587. if (res.code == 0) {
  588. GameObject.FindObjectOfType<LoginMgr>().showLoginView();
  589. }
  590. }
  591. ));
  592. }
  593. #region Picker
  594. [SerializeField] GameObject datePickerPrefab;
  595. public void OpenDatePicker() {
  596. GameObject o = GameObject.Instantiate(datePickerPrefab);
  597. //o.GetComponentInChildren<JC.Unity.Picker.DatePickerGroup>().onEnter += (JC.Unity.Picker.DatePickerGroup picker) => {
  598. // GetInputField(registerInBirthday).text = picker.GetSelectDateStr();
  599. //};
  600. o.GetComponentInChildren<DatePickerGroupNew>().onEnter += (DatePickerGroupNew picker) =>
  601. {
  602. GetInputField(registerInBirthday).text = picker.GetSelectDateStr();
  603. };
  604. }
  605. [SerializeField] GameObject locationPickerPrefab;
  606. private string countryCode = "", stateCode = "", cityCode = "";
  607. public void OpenLocationPicker() {
  608. // GameObject o = GameObject.Instantiate(locationPickerPrefab);
  609. // o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
  610. // countryCode = info.GetCountryRegion().Item2;
  611. // stateCode = info.GetState().Item2;
  612. // cityCode = info.GetCity().Item2;
  613. // GetInputField(registerInLocation).text =
  614. // info.GetCountryRegion().Item1 + " " +
  615. // info.GetState().Item1 + " " +
  616. // info.GetCity().Item1;
  617. // };
  618. //2022-12-6 gps获取地理位置
  619. GetLocation();
  620. }
  621. void GetLocation()
  622. {
  623. try
  624. {
  625. System.Action eOnAgree = () => {
  626. GPSTool.GetAddress((address) => {
  627. if (address != null) {
  628. countryCode = address[0];
  629. stateCode = address[1];
  630. cityCode = address[2];
  631. GetInputField(registerInLocation).text =
  632. countryCode + " " +
  633. stateCode + " " +
  634. cityCode;
  635. }
  636. });
  637. };
  638. if (!HomeView.ShowProminentBeforeConnectBLE(eOnAgree)) eOnAgree.Invoke();
  639. }
  640. catch (System.Exception e) { Debug.LogError(e); }
  641. }
  642. #endregion
  643. }