RegisterView.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. Text registerText = registerInUser.transform.Find("Text").GetComponent<Text>();
  187. registerText.text = TextAutoLanguage2.GetTextByKey("register_email2");
  188. Text inputRelateAccountText = _inputRelateAccount.transform.Find("Placeholder").GetComponent<Text>();
  189. inputRelateAccountText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email1");
  190. //输入框文案
  191. Text registerInPhoneText = registerInPhone.transform.Find("Text").GetComponent<Text>();
  192. registerInPhoneText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email001");
  193. //输入框提示
  194. Text _tempCodeText = _inputValidateCode.transform.Find("Placeholder").GetComponent<Text>();
  195. //_tempCodeText.fontSize = languageEnum == LanguageEnum.Chinese ? 24 : 20;
  196. _tempCodeText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email201"); //RelateValidateView-email2
  197. //发送按钮
  198. registerInPhone.transform.Find("GameObject/Send/Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("common_send"); //RelateValidateView-email3
  199. if (TextAutoLanguage2.GetLanguage() == LanguageEnum.Japan) {
  200. //registerText.fontSize = 24;
  201. //registerInPhoneText.fontSize = 24;
  202. _tempCodeText.fontSize = 24;
  203. inputRelateAccountText.fontSize = 24;
  204. }
  205. }
  206. else if (_LoginValidateType == LoginValidateType.Phone)
  207. {
  208. _inputRelateAccount.contentType = InputField.ContentType.IntegerNumber;
  209. _inputRelateAccount.characterLimit = 11;
  210. Text registerText = registerInUser.transform.Find("Text").GetComponent<Text>();
  211. registerText.text = TextAutoLanguage2.GetTextByKey("register_phone2");
  212. Text inputRelateAccountText = _inputRelateAccount.transform.Find("Placeholder").GetComponent<Text>();
  213. inputRelateAccountText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-phone1");
  214. //手机部分的验证码也保持和邮件的文案一样
  215. Text registerInPhoneText = registerInPhone.transform.Find("Text").GetComponent<Text>();
  216. registerInPhoneText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email001");//("RelateValidateView-phone0");
  217. Text _tempCodeText = _inputValidateCode.transform.Find("Placeholder").GetComponent<Text>();
  218. //_tempCodeText.fontSize = languageEnum == LanguageEnum.Chinese ? 24 : 20;
  219. _tempCodeText.text = TextAutoLanguage2.GetTextByKey("RelateValidateView-email201");//("RelateValidateView-phone2");
  220. registerInPhone.transform.Find("GameObject/Send/Text").GetComponent<Text>().text = TextAutoLanguage2.GetTextByKey("common_send");//RelateValidateView-phone3
  221. if (TextAutoLanguage2.GetLanguage() == LanguageEnum.Japan)
  222. {
  223. //registerText.fontSize = 24;
  224. //registerInPhoneText.fontSize = 24;
  225. _tempCodeText.fontSize = 24;
  226. inputRelateAccountText.fontSize = 24;
  227. }
  228. }
  229. }
  230. [SerializeField] GameObject _prefabValidateJigsawView;
  231. static long _throttlerBtnSend_phone_reg = 0;
  232. long _throttlerBtnSend_reg
  233. {
  234. get
  235. {
  236. return _throttlerBtnSend_phone_reg;
  237. }
  238. set
  239. {
  240. _throttlerBtnSend_phone_reg = value;
  241. }
  242. }
  243. public void OnClick_SendCode() {
  244. if (_LoginValidateType == LoginValidateType.Email)
  245. {
  246. string email = _inputRelateAccount.text;
  247. sendCodeAccount = email;
  248. if (!ValidateHelper.IsEmail(email))
  249. {
  250. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a0"));
  251. return;
  252. }
  253. }
  254. else if (_LoginValidateType == LoginValidateType.Phone)
  255. {
  256. //记录一个发送code时候的号码,下一步时候判定一下是否同一个号码,不是的话提示重新发送,和检测一下合理性
  257. string phone = _inputRelateAccount.text;
  258. sendCodeAccount = phone;
  259. if (!ValidateHelper.IsMobilePhone(phone))
  260. {
  261. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a1"));
  262. return;
  263. }
  264. }
  265. //验证码再次发送需要间隔60秒
  266. long gapTime = TimeUtils.GetTimestamp() - _throttlerBtnSend_reg;
  267. long maxTime = 60 * 1000;
  268. if (gapTime < maxTime)
  269. {
  270. long second = (maxTime - gapTime) / 1000;
  271. if (second <= 0) second = 1;
  272. PopupMgr.ins.ShowTip(string.Format(TextAutoLanguage2.GetTextByKey("RelateValidateView-a2"), second));
  273. return;
  274. }
  275. //打开拼图验证
  276. GameObject gameObjectValidateJigsawView = Instantiate(_prefabValidateJigsawView);
  277. //CanvasUtils.PlusSortOrder(gameObject, gameObjectValidateJigsawView, 1);
  278. ValidateJigsawView validateJigsawView = gameObjectValidateJigsawView.GetComponent<ValidateJigsawView>();
  279. validateJigsawView.onComplete = RequestSendValidateCode;
  280. validateJigsawView.SetTextLabel(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_label"));
  281. validateJigsawView.SetTextTip(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_tip"));
  282. validateJigsawView.SetTextOK(TextAutoLanguage2.GetTextByKey("ValidateJigsawView_ok"));
  283. }
  284. bool bSend = false;
  285. private void Update()
  286. {
  287. if (bSend)
  288. {
  289. //验证码再次发送需要间隔60秒
  290. if (SendBtn.IsInteractable()) SendBtn.interactable = false;
  291. long gapTime = TimeUtils.GetTimestamp() - _throttlerBtnSend_reg;
  292. long maxTime = 60 * 1000;
  293. long second = (maxTime - gapTime) / 1000;
  294. if (second <= 0) second = 0;
  295. SendBtnText.text = second + " S";
  296. if (second == 0)
  297. {
  298. bSend = false;
  299. SendBtnText.text = TextAutoLanguage2.GetTextByKey("common_send");
  300. }
  301. }
  302. else {
  303. //停止计时
  304. if (!SendBtn.IsInteractable()) SendBtn.interactable = true;
  305. }
  306. }
  307. void RequestSendValidateCode()
  308. {
  309. //限流时间点记录
  310. _throttlerBtnSend_reg = TimeUtils.GetTimestamp();
  311. bSend = true;
  312. //请求服务端接口
  313. if (_LoginValidateType == LoginValidateType.Email)
  314. {
  315. string email = _inputRelateAccount.text;
  316. StartCoroutine(EmailValidateController.Instance.SendEmailValidateCode(email, (res) => {
  317. if (res.code == 0) PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b0"));
  318. else PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b1"));
  319. }));
  320. }
  321. else if (_LoginValidateType == LoginValidateType.Phone)
  322. {
  323. string phone = _inputRelateAccount.text;
  324. StartCoroutine(PhoneValidateController.Instance.SendPhoneValidateCode(phone, (res) => {
  325. if (res.code == 0) PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b2"));
  326. else PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("RelateValidateView-b3"));
  327. }));
  328. }
  329. }
  330. Throttler _throttlerBtnSubmit = new Throttler(3000);
  331. public void OnClick_BtnSubmit()
  332. {
  333. if (_LoginValidateType == LoginValidateType.Email)
  334. {
  335. string email = _inputRelateAccount.text;
  336. if (!ValidateHelper.IsEmail(email))
  337. {
  338. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a0"));
  339. return;
  340. }
  341. }
  342. else if (_LoginValidateType == LoginValidateType.Phone)
  343. {
  344. string phone = _inputRelateAccount.text;
  345. if (!ValidateHelper.IsMobilePhone(phone))
  346. {
  347. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a1"));
  348. return;
  349. }
  350. }
  351. string code = _inputValidateCode.text;
  352. if (code.Length != 6)
  353. {
  354. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a3"));
  355. return;
  356. }
  357. if (!_throttlerBtnSubmit.CanPass())
  358. {
  359. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  360. return;
  361. }
  362. RequestSubmit();
  363. }
  364. void RequestSubmit()
  365. {
  366. if (_LoginValidateType == LoginValidateType.Email)
  367. {
  368. string email = _inputRelateAccount.text;
  369. string code = _inputValidateCode.text;
  370. StartCoroutine(EmailValidateController.Instance.ValidateEmail(email, code, (res) => {
  371. if (res.code == 0)
  372. {
  373. JObject data = res.data as JObject;
  374. string arg0 = data.Value<string>("email");
  375. long arg1 = data.Value<long>("timestamp");
  376. string arg2 = data.Value<string>("sign");
  377. Debug.Log($"邮箱验证成功 {arg0} {arg1} {arg2}");
  378. _bindingEmail = arg0;
  379. RegisterNext();
  380. }
  381. else PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-c0"));
  382. }));
  383. }
  384. else if (_LoginValidateType == LoginValidateType.Phone)
  385. {
  386. string phone = _inputRelateAccount.text;
  387. string code = _inputValidateCode.text;
  388. StartCoroutine(PhoneValidateController.Instance.ValidatePhone(phone, code, (res) => {
  389. if (res.code == 0)
  390. {
  391. JObject data = res.data as JObject;
  392. string arg0 = data.Value<string>("phone");
  393. long arg1 = data.Value<long>("timestamp");
  394. string arg2 = data.Value<string>("sign");
  395. Debug.Log($"手机验证成功 {arg0} {arg1} {arg2}");
  396. _bindingPhone = arg0;
  397. RegisterNext();
  398. }
  399. else PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-c1"));
  400. }));
  401. }
  402. }
  403. private string usrRecord = "";
  404. private string pwdRecord = "";
  405. JCUnityLib.Throttler throttlerRegisterNext = new JCUnityLib.Throttler(2000);
  406. public void onDetectPassword() {
  407. InputField pwd1 = GetInputField(registerInPWD1);
  408. InputField pwd2 = GetInputField(registerInPWD2);
  409. passwordTip.SetActive(pwd1.text != pwd2.text);
  410. }
  411. void TestNav() {
  412. InputField user = GetGameObjectInputField(registerInUser);
  413. InputField pwd1 = GetInputField(registerInPWD1);
  414. usrRecord = user.text;
  415. pwdRecord = pwd1.text;
  416. InputField nickname = GetInputField(registerInNickname);
  417. if (_LoginValidateType == LoginValidateType.Email)
  418. {
  419. //邮箱裁剪一下
  420. string[] arry = usrRecord.Trim().Split("@");
  421. nickname.text = arry[0];
  422. }
  423. else
  424. {
  425. //手机直接设置电话号码
  426. nickname.text = usrRecord;
  427. }
  428. InitPage(true);
  429. LoginView.ins.FillLoginInput(usrRecord, pwdRecord);
  430. }
  431. public void RegisterNext()
  432. {
  433. //TestNav();
  434. //return;
  435. //检测是否绑定手机号和邮箱号,没有进行绑定。绑定后再调用此流程
  436. if (!CommonConfig.banBindRelateAccount)
  437. {
  438. if (string.IsNullOrEmpty(_bindingEmail) && string.IsNullOrEmpty(_bindingPhone))
  439. {
  440. OnClick_BtnSubmit();
  441. return;
  442. }
  443. }
  444. //这里变成手机号或者邮箱号了
  445. if (_LoginValidateType == LoginValidateType.Email)
  446. {
  447. if (!ValidateHelper.IsEmail(_inputRelateAccount.text))
  448. {
  449. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a0"));
  450. return;
  451. }
  452. }
  453. else if (_LoginValidateType == LoginValidateType.Phone)
  454. {
  455. if (!ValidateHelper.IsMobilePhone(_inputRelateAccount.text))
  456. {
  457. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a1"));
  458. return;
  459. }
  460. }
  461. //更换账户后请重新发送验证码
  462. if (sendCodeAccount != _inputRelateAccount.text)
  463. {
  464. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-a11"));
  465. return;
  466. }
  467. //if (user.text.Length < 6) {
  468. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("账号长度至少6位"));
  469. // return;
  470. //}
  471. InputField pwd1 = GetInputField(registerInPWD1);
  472. if (pwd1.text.Length < 6) {
  473. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("密码长度至少6位"));
  474. return;
  475. }
  476. InputField pwd2 = GetInputField(registerInPWD2);
  477. if (pwd1.text != pwd2.text) {
  478. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("两次输入的密码不一致"));
  479. passwordTip.SetActive(true);
  480. return;
  481. }
  482. // if (!CommonConfig.banBindRelateAccount)
  483. // {
  484. // if (string.IsNullOrEmpty(_bindingEmail) && string.IsNullOrEmpty(_bindingPhone)) {
  485. // if (CommonConfig.serverIndex == 0) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("至少需要绑定邮箱号或者手机号"));
  486. // else PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("尚未绑定邮箱号"));
  487. // return;
  488. // }
  489. // }
  490. //if (registerInEmail.activeSelf && string.IsNullOrEmpty(_bindingEmail)) {
  491. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("尚未绑定邮箱号"));
  492. // return;
  493. //}
  494. //if (registerInPhone.activeSelf && string.IsNullOrEmpty(_bindingPhone)) {
  495. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("尚未绑定手机号"));
  496. // return;
  497. //}
  498. InputField captcha = GetGameObjectInputField(registerInCaptcha);
  499. if (!captcha.text.Equals(captcha_Register_str)) {
  500. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("验证码错误"));
  501. return;
  502. }
  503. if (!AgreenmentOption.ins.IsAgreementChecked()) {
  504. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
  505. return;
  506. }
  507. if (throttlerRegisterNext.CanPass() == false) {
  508. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  509. return;
  510. }
  511. usrRecord = _inputRelateAccount.text;
  512. pwdRecord = pwd1.text;
  513. if (CommonConfig.banBindRelateAccount)
  514. {
  515. StartCoroutine(LoginController.Instance.Register(
  516. usrRecord, pwdRecord, (res) => {
  517. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  518. if (res.code == 0) {
  519. //设置默认名字,为当前注册的账户信息
  520. InputField nickname = GetInputField(registerInNickname);
  521. if (_LoginValidateType == LoginValidateType.Email)
  522. {
  523. //邮箱裁剪一下
  524. //string[] arry = usrRecord.Trim().Split("@");
  525. //nickname.text = arry[0];
  526. nickname.text = usrRecord;
  527. }
  528. else {
  529. //手机直接设置电话号码
  530. nickname.text = usrRecord;
  531. }
  532. InitPage(true); //前往完善用户信息
  533. LoginView.ins.FillLoginInput(usrRecord, pwdRecord);
  534. }
  535. }
  536. ));
  537. return;
  538. }
  539. StartCoroutine(LoginController.Instance.Register2(
  540. usrRecord, pwdRecord, _bindingEmail, _bindingPhone, (res) => {
  541. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  542. if (res.code == 0) {
  543. //设置默认名字,为当前注册的账户信息
  544. InputField nickname = GetInputField(registerInNickname);
  545. if (_LoginValidateType == LoginValidateType.Email)
  546. {
  547. //邮箱裁剪一下
  548. //string[] arry = usrRecord.Trim().Split("@");
  549. nickname.text = usrRecord;
  550. }
  551. else
  552. {
  553. //手机直接设置电话号码
  554. nickname.text = usrRecord;
  555. }
  556. InitPage(true); //前往完善用户信息
  557. LoginView.ins.FillLoginInput(usrRecord, pwdRecord);
  558. }
  559. }
  560. ));
  561. }
  562. JCUnityLib.Throttler throttlerRegisterSave = new JCUnityLib.Throttler(2000);
  563. public void RegisterSave() {
  564. InputField nickname = GetInputField(registerInNickname);
  565. string text_nickname = nickname.text.Trim();
  566. if (text_nickname.Length == 0) {
  567. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请输入游戏昵称"));
  568. return;
  569. }
  570. int gender = 0;
  571. Transform toggleGroup = registerInGender.transform.Find("ToggleGroup");
  572. for (int i = 0; i < toggleGroup.childCount; i++) {
  573. if (toggleGroup.GetChild(i).GetComponent<Toggle>().isOn) {
  574. gender = i == 0 ? 1 : 2;
  575. break;
  576. }
  577. }
  578. InputField birthday = GetInputField(registerInBirthday);
  579. string text_birthday = birthday.text;
  580. if (text_birthday.Length != 10) {
  581. text_birthday = "2000-01-01";
  582. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写出生日期"));
  583. // return;
  584. }
  585. InputField location = GetInputField(registerInLocation);
  586. if (location.text.Length == 0) {
  587. countryCode = "";
  588. stateCode = "";
  589. cityCode = "";
  590. // PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("未填写所在地区"));
  591. // return;
  592. }
  593. if (!AgreenmentOption.ins.IsAgreementChecked()) {
  594. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("请阅读并同意App协议"));
  595. return;
  596. }
  597. if (throttlerRegisterSave.CanPass() == false) {
  598. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
  599. return;
  600. }
  601. StartCoroutine(LoginController.Instance.CompleteUserInfo(
  602. usrRecord, pwdRecord, text_nickname, gender, text_birthday,
  603. countryCode, stateCode, cityCode
  604. ,(res) => {
  605. PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
  606. if (res.code == 0) {
  607. GameObject.FindObjectOfType<LoginMgr>().showLoginView();
  608. }
  609. }
  610. ));
  611. }
  612. #region Picker
  613. [SerializeField] GameObject datePickerPrefab;
  614. public void OpenDatePicker() {
  615. GameObject o = GameObject.Instantiate(datePickerPrefab);
  616. //o.GetComponentInChildren<JC.Unity.Picker.DatePickerGroup>().onEnter += (JC.Unity.Picker.DatePickerGroup picker) => {
  617. // GetInputField(registerInBirthday).text = picker.GetSelectDateStr();
  618. //};
  619. o.GetComponentInChildren<DatePickerGroupNew>().onEnter += (DatePickerGroupNew picker) =>
  620. {
  621. GetInputField(registerInBirthday).text = picker.GetSelectDateStr();
  622. };
  623. }
  624. [SerializeField] GameObject locationPickerPrefab;
  625. private string countryCode = "", stateCode = "", cityCode = "";
  626. public void OpenLocationPicker() {
  627. // GameObject o = GameObject.Instantiate(locationPickerPrefab);
  628. // o.GetComponentInChildren<JC.Unity.Picker.LocationPickerGroup>().onEnter += (JC.Unity.Picker.LocationInfo info) => {
  629. // countryCode = info.GetCountryRegion().Item2;
  630. // stateCode = info.GetState().Item2;
  631. // cityCode = info.GetCity().Item2;
  632. // GetInputField(registerInLocation).text =
  633. // info.GetCountryRegion().Item1 + " " +
  634. // info.GetState().Item1 + " " +
  635. // info.GetCity().Item1;
  636. // };
  637. //2022-12-6 gps获取地理位置
  638. GetLocation();
  639. }
  640. void GetLocation()
  641. {
  642. try
  643. {
  644. System.Action eOnAgree = () => {
  645. GPSTool.GetAddress((address) => {
  646. if (address != null) {
  647. countryCode = address[0];
  648. stateCode = address[1];
  649. cityCode = address[2];
  650. GetInputField(registerInLocation).text =
  651. countryCode + " " +
  652. stateCode + " " +
  653. cityCode;
  654. }
  655. });
  656. };
  657. if (!HomeView.ShowProminentBeforeConnectBLE(eOnAgree)) eOnAgree.Invoke();
  658. }
  659. catch (System.Exception e) { Debug.LogError(e); }
  660. }
  661. #endregion
  662. }