RegisterView.cs 27 KB

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