| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using JCUnityLib;
- using JCUnityLib.UI;
- using Newtonsoft.Json.Linq;
- using System.Text.RegularExpressions;
- public class RetrievePasswordView : MonoBehaviour, MenuBackInterface
- {
- void Start()
- {
- PersistenHandler.ins?.menuBackCtr.views.Add(this);
-
- InitRetrieveValidate();
- InitSelectUsername();
- InitResetPassword();
- transform.Find("BtnBack").GetComponentInChildren<Button>().onClick.AddListener(() => Destroy(gameObject));
- }
- void OnDestroy()
- {
- PersistenHandler.ins?.menuBackCtr.views.Remove(this);
- }
- public bool OnMenuBack()
- {
- Destroy(gameObject);
- return true;
- }
- void ActivePage(int pageID)
- {
- _retrieveValidate.gameObject.SetActive(pageID == 0);
- _selectUsername.gameObject.SetActive(pageID == 1);
- _resetPassword.gameObject.SetActive(pageID == 2);
- }
- RectTransform _retrieveValidate;
- enum RetrieveValidateType { Email, Phone }
- RetrieveValidateType _retrieveValidateType = RetrieveValidateType.Email;
- void InitRetrieveValidate()
- {
- _retrieveValidate = transform.Find("RetrieveValidate") as RectTransform;
- var btnByEmail = _retrieveValidate.Find("BtnByEmail").GetComponent<Button>();
- var btnByPhone = _retrieveValidate.Find("BtnByPhone").GetComponent<Button>();
- btnByEmail.onClick.AddListener(() => OnClick_RetrieveValidateType(RetrieveValidateType.Email));
- btnByPhone.onClick.AddListener(() => OnClick_RetrieveValidateType(RetrieveValidateType.Phone));
- btnByPhone.gameObject.SetActive(CommonConfig.serverIndex == 0);
- }
- void OnClick_RetrieveValidateType(RetrieveValidateType retrieveValidateType)
- {
- _retrieveValidateType = retrieveValidateType;
- RelateValidateView relateValidateView =
- Instantiate(SceneResourceManager.Instance.GetPrefab("RelateValidateView"))
- .GetComponent<RelateValidateView>();
- CanvasUtils.PlusSortOrder(gameObject, relateValidateView.gameObject, 1);
- if (_retrieveValidateType == RetrieveValidateType.Email) relateValidateView.InitForEmail();
- if (_retrieveValidateType == RetrieveValidateType.Phone) relateValidateView.InitForPhone();
- relateValidateView.onValidateSuccess = (a, b, c) => {
- relateValidateView.BanButtons();
- if (_retrieveValidateType == RetrieveValidateType.Email)
- {
- string email = a; long timestamp = b; string sign = c;
- StartCoroutine(LoginController.Instance.ListUsernamesByEmail(email, timestamp, sign, (res) => {
- relateValidateView.CloseView();
- if (res.code == 0)
- {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-pass0"));
- GoToSelectUsername(res.data as JArray);
- }
- else if (res.code == -1) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RetrievePasswordView-tip0"));
- else if (res.code == -2) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RetrievePasswordView-tip1"));
- }));
- }
- else if (_retrieveValidateType == RetrieveValidateType.Phone)
- {
- string phone = a; long timestamp = b; string sign = c;
- StartCoroutine(LoginController.Instance.ListUsernamesByPhone(phone, timestamp, sign, (res) => {
- relateValidateView.CloseView();
- if (res.code == 0)
- {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-pass0"));
- GoToSelectUsername(res.data as JArray);
- }
- else if (res.code == -1) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RetrievePasswordView-tip0"));
- else if (res.code == -2) PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RetrievePasswordView-tip2"));
- }));
- }
- };
- }
- RectTransform _selectUsername;
- string _currentUsername;
- long _currentUsernameTimestamp;
- string _currentUsernameSign;
- void InitSelectUsername()
- {
- _selectUsername = transform.Find("SelectUsername") as RectTransform;
- }
- void GoToSelectUsername(JArray jArray)
- {
- ActivePage(1);
- Transform content = _selectUsername.Find("Scroll View/Viewport/Content");
- GameObject prefab = content.Find("Username").gameObject;
- prefab.SetActive(false);
- foreach (var item in jArray)
- {
- string username = item.Value<string>("username");
- long timestamp = item.Value<long>("timestamp");
- string sign = item.Value<string>("sign");
- var o = Instantiate(prefab, content);
- o.GetComponentInChildren<Text>().text = username;
- o.GetComponent<Button>().onClick.AddListener(() => {
- _currentUsername = username;
- _currentUsernameTimestamp = timestamp;
- _currentUsernameSign = sign;
- GoToResetPassword();
- });
- o.SetActive(true);
- }
- }
- RectTransform _resetPassword;
- Text _page2_text_Username;
- InputField _page2_input_Password;
- InputField _page2_input_Password2;
- Button _page2_btnSubmit;
- JCUnityLib.Throttler _throttlerBtnSubmit = new JCUnityLib.Throttler(2000);
- void InitResetPassword()
- {
- _resetPassword = transform.Find("ResetPassword") as RectTransform;
- var layout = _resetPassword.Find("Layout");
- _page2_text_Username = layout.Find("Username").GetComponentInChildren<Text>();
- _page2_input_Password = layout.Find("Password").GetComponentInChildren<InputField>();
- _page2_input_Password2 = layout.Find("Password2").GetComponentInChildren<InputField>();
- _page2_btnSubmit = layout.Find("BtnSubmit").GetComponent<Button>();
- //limitInput
- InputField[] inputs = {_page2_input_Password, _page2_input_Password2};
- foreach (var input in inputs) {
- input.onValueChanged.AddListener(delegate(string text) {
- Match match = new Regex("[^A-Za-z0-9]").Match(text);
- if (match.Success) {
- input.text = text.Replace(match.Value, "");
- }
- });
- }
- //submit
- _page2_btnSubmit.onClick.AddListener(() => {
- if (_page2_input_Password.text.Length < 6) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("密码长度至少6位"));
- return;
- }
- if (_page2_input_Password.text != _page2_input_Password2.text) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("两次输入的密码不一致"));
- return;
- }
- if (_throttlerBtnSubmit.CanPass() == false) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey("操作过于频繁"));
- return;
- }
- StartCoroutine(LoginController.Instance.ResetPassword(_currentUsernameSign, _currentUsernameTimestamp, _currentUsername, _page2_input_Password.text, (res) => {
- if (res.code == 0) {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RetrievePasswordView-tip3"));
- _page2_btnSubmit.interactable = false;
- StartCoroutine(DelayDestroy());
- } else {
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RetrievePasswordView-tip4"));
- }
- }));
- });
- }
- void GoToResetPassword()
- {
- ActivePage(2);
- _page2_text_Username.text = _currentUsername;
- _page2_input_Password.text = "";
- _page2_input_Password2.text = "";
- }
- IEnumerator DelayDestroy()
- {
- yield return new WaitForSeconds(1);
- Destroy(gameObject);
- }
- }
|