GetPassPanel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace LoyalSoftSDK
  7. {
  8. public class GetPassPanel : BaseUIForm
  9. {
  10. private Text errText;
  11. private InputField phoneInput;
  12. private InputField codeInput;
  13. private InputField passInput;
  14. private InputField passAginIput;
  15. private GameObject codeBtn;
  16. private GameObject submitBtn;
  17. private GameObject backButton;
  18. private Text codeBtnText;
  19. // Use this for initialization
  20. private string editAccount;
  21. private string editPassWord;
  22. private string editPassAgin;
  23. private string editCode;
  24. private bool isGetCode;
  25. private DateTime getCodeTime;
  26. private int reGetCodeTime = 120;
  27. public override void Init()
  28. {
  29. curUIType = UIType.Normal;
  30. errText = this.transform.Find("BackPanel/ErrText").gameObject.GetComponent<Text>();
  31. phoneInput = this.transform.Find("BackPanel/PhoneInput").gameObject.GetComponent<InputField>();
  32. phoneInput.onEndEdit.AddListener(OnPhoneInputEndEdit);
  33. codeInput = this.transform.Find("BackPanel/CodeInput").gameObject.GetComponent<InputField>();
  34. codeInput.onEndEdit.AddListener(OnCodeInputEndEdit);
  35. passInput = this.transform.Find("BackPanel/PassInput").gameObject.GetComponent<InputField>();
  36. passInput.onEndEdit.AddListener(OnPassInputEndEdit);
  37. passAginIput = this.transform.Find("BackPanel/PassAginInput").gameObject.GetComponent<InputField>();
  38. passAginIput.onEndEdit.AddListener(OnPassAginIputEndEdit);
  39. codeBtn = this.transform.Find("BackPanel/CodeButton").gameObject;
  40. EventTriggerListener.Get(codeBtn).onClick = OnCodeBtnClick;
  41. submitBtn = this.transform.Find("BackPanel/SubmitButton").gameObject;
  42. EventTriggerListener.Get(submitBtn).onClick = OnSubmitBtnClick;
  43. backButton = this.transform.Find("BackPanel/BackButton").gameObject;
  44. EventTriggerListener.Get(backButton).onClick = OnBackButtonClick;
  45. codeBtnText = this.transform.Find("BackPanel/CodeButton/Text").gameObject.GetComponent<Text>();
  46. }
  47. public override void Display(BaseUIForm _parent, Dictionary<string, string> data)
  48. {
  49. phoneInput.text = "";
  50. codeInput.text = "";
  51. passInput.text = "";
  52. passAginIput.text = "";
  53. errText.text = "";
  54. string action;
  55. data.TryGetValue("action", out action);
  56. switch (action)
  57. {
  58. case "getpass":
  59. data.TryGetValue("account", out editAccount);
  60. phoneInput.text = editAccount;
  61. break;
  62. }
  63. base.Display(_parent, data);
  64. }
  65. private bool IsGetCode
  66. {
  67. get
  68. {
  69. return isGetCode;
  70. }
  71. set
  72. {
  73. isGetCode = value;
  74. if (isGetCode)
  75. {
  76. EventTriggerListener.Get(codeBtn).onClick = null;
  77. codeBtn.transform.GetComponent<Button>().interactable = false;
  78. }
  79. else
  80. {
  81. EventTriggerListener.Get(codeBtn).onClick = OnCodeBtnClick;
  82. codeBtn.transform.GetComponent<Button>().interactable = true;
  83. codeBtnText.text = "获取验证码";
  84. }
  85. }
  86. }
  87. private void OnPhoneInputEndEdit(string phone)
  88. {
  89. editAccount = phone;
  90. errText.text = RegexInspection.AccountInspection(editAccount);
  91. }
  92. private void OnCodeInputEndEdit(string code)
  93. {
  94. editCode = code;
  95. errText.text = RegexInspection.CodeInspection(editCode);
  96. }
  97. private void OnPassInputEndEdit(string pass)
  98. {
  99. editPassWord = pass;
  100. errText.text = RegexInspection.PassWordInspection(editPassWord);
  101. }
  102. private void OnPassAginIputEndEdit(string passAgin)
  103. {
  104. editPassAgin = passAgin;
  105. if (string.IsNullOrEmpty(editPassWord))
  106. {
  107. return;
  108. }
  109. if (!editPassAgin.Equals(editPassWord))
  110. {
  111. errText.text = "两次输入密码不一致";
  112. }
  113. }
  114. private void OnCodeBtnClick(GameObject go)
  115. {
  116. //Dictionary<string, string> dataMsg = new Dictionary<string, string>();
  117. //dataMsg.Add("message", "验证码已发送!");
  118. //UIFormManager.GetInstance().ShowUIForm("MessagePanel", null, dataMsg);
  119. //return;
  120. errText.text = RegexInspection.AccountInspection(editAccount);
  121. if (!string.IsNullOrEmpty(errText.text))
  122. {
  123. return;
  124. }
  125. Dictionary<string, object> sendPostDic = new Dictionary<string, object>();
  126. string senStr;
  127. string[] code = new string[2];
  128. code[0] = editAccount;
  129. code[1] = "言灵世界";
  130. sendPostDic.Add("uid", "wanggangzero");
  131. sendPostDic.Add("ope", "604");
  132. sendPostDic.Add("cmd", "4002");
  133. sendPostDic.Add("paras", code);
  134. sendPostDic.Add("clientVer", "1.0.1");
  135. sendPostDic.Add("sign", "");
  136. senStr = MiniJSON.Json.Serialize(sendPostDic);
  137. StartCoroutine(UserManager.GetInstance().NetRequest(Config.api_url, senStr, CodeCallBack));
  138. }
  139. private void OnSubmitBtnClick(GameObject go)
  140. {
  141. errText.text = RegexInspection.AccountInspection(editAccount);
  142. if (!string.IsNullOrEmpty(errText.text))
  143. {
  144. return;
  145. }
  146. errText.text = RegexInspection.PassWordInspection(editPassWord);
  147. if (!string.IsNullOrEmpty(errText.text))
  148. {
  149. return;
  150. }
  151. if (!editPassAgin.Equals(editPassWord))
  152. {
  153. errText.text = "两次输入密码不一致";
  154. }
  155. if (!string.IsNullOrEmpty(errText.text))
  156. {
  157. return;
  158. }
  159. errText.text = RegexInspection.CodeInspection(editCode);
  160. if (!string.IsNullOrEmpty(errText.text))
  161. {
  162. return;
  163. }
  164. Dictionary<string, object> sendPostDic = new Dictionary<string, object>();
  165. string senStr;
  166. string[] code = new string[3];
  167. code[0] = editAccount;
  168. code[1] = RegexInspection.GetMD5Hash(editPassWord); ;
  169. code[2] = editCode;
  170. sendPostDic.Add("uid", "wanggangzero");
  171. sendPostDic.Add("ope", "600");
  172. sendPostDic.Add("cmd", "6007");
  173. sendPostDic.Add("paras", code);
  174. sendPostDic.Add("clientVer", "1.0.1");
  175. sendPostDic.Add("sign", "");
  176. senStr = MiniJSON.Json.Serialize(sendPostDic);
  177. StartCoroutine(UserManager.GetInstance().NetRequest(Config.api_url, senStr, SubmitCallBack));
  178. }
  179. private void OnBackButtonClick(GameObject go)
  180. {
  181. GoBackParent();
  182. }
  183. private void CodeCallBack(string code, string data)
  184. {
  185. if (code.Equals("succees"))
  186. {
  187. Dictionary<string, object> jsonMap = MiniJSON.Json.Deserialize(data) as Dictionary<string, object>;
  188. string errCode = jsonMap["err"].ToString();
  189. if (errCode.Equals("0"))
  190. {
  191. //succees----{ "uid":"wanggangzero","msgid":null,"err":0,"result":null,"ts":1527841566,"tag":{ },"sig":null}
  192. Dictionary<string, string> dataMsg = new Dictionary<string, string>();
  193. dataMsg.Add("message", "验证码已发送!");
  194. UIFormManager.GetInstance().ShowUIForm("MessagePanel",null, dataMsg);
  195. IsGetCode = true;
  196. getCodeTime = DateTime.Now;
  197. }
  198. else
  199. {
  200. IsGetCode = false;
  201. errText.text = (jsonMap["tag"] as Dictionary<string, object>)["errmsg"].ToString();
  202. }
  203. }
  204. else
  205. {
  206. IsGetCode = false;
  207. Debug.LogError("网络通信出错!---" + data);
  208. errText.text = "网络出错,请稍候再试!";
  209. }
  210. }
  211. private void SubmitCallBack(string code, string data)
  212. {
  213. if (code.Equals("succees"))
  214. {
  215. Dictionary<string, object> jsonMap = MiniJSON.Json.Deserialize(data) as Dictionary<string, object>;
  216. string errCode = jsonMap["err"].ToString();
  217. if (errCode.Equals("0"))
  218. {
  219. Dictionary<string, string> dataMsg = new Dictionary<string, string>();
  220. dataMsg.Add("message", "密码已修改!");
  221. UIFormManager.GetInstance().ShowUIForm("MessagePanel", null, dataMsg);
  222. //succees----{ "uid":"wanggangzero","msgid":null,"err":0,"result":null,"ts":1527841566,"tag":{ },"sig":null}
  223. TimeSpan toNow = DateTime.Now - new DateTime(1970, 1, 1);
  224. UserManager.GetInstance().SetSaveUserData(editAccount, RegexInspection.GetMD5Hash(editPassWord), ((int)toNow.TotalSeconds).ToString());
  225. Hiding();
  226. Dictionary<string, string> dataLogin = new Dictionary<string, string>();
  227. dataLogin.Add("action", "star");
  228. UIFormManager.GetInstance().ShowUIForm("LoginPanel", null, dataLogin);
  229. }
  230. else
  231. {
  232. errText.text = (jsonMap["tag"] as Dictionary<string, object>)["errmsg"].ToString();
  233. }
  234. }
  235. else
  236. {
  237. Debug.LogError("网络通信出错!---" + data);
  238. errText.text = "网络出错,请稍候再试!";
  239. }
  240. }
  241. // Update is called once per frame
  242. void Update()
  243. {
  244. if (IsGetCode)
  245. {
  246. TimeSpan toNow = DateTime.Now - getCodeTime;
  247. int leftTime = reGetCodeTime - (int)toNow.TotalSeconds;
  248. if (leftTime > 0)
  249. {
  250. codeBtnText.text = "重新获取(" + leftTime + ")";
  251. }
  252. else
  253. {
  254. IsGetCode = false;
  255. }
  256. }
  257. }
  258. }
  259. }