RegisterView.cs 28 KB

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