123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- namespace LoyalSoftSDK
- {
- public class GetPassPanel : BaseUIForm
- {
- private Text errText;
- private InputField phoneInput;
- private InputField codeInput;
- private InputField passInput;
- private InputField passAginIput;
- private GameObject codeBtn;
- private GameObject submitBtn;
- private GameObject backButton;
- private Text codeBtnText;
- // Use this for initialization
- private string editAccount;
- private string editPassWord;
- private string editPassAgin;
- private string editCode;
- private bool isGetCode;
- private DateTime getCodeTime;
- private int reGetCodeTime = 120;
- public override void Init()
- {
- curUIType = UIType.Normal;
- errText = this.transform.Find("BackPanel/ErrText").gameObject.GetComponent<Text>();
- phoneInput = this.transform.Find("BackPanel/PhoneInput").gameObject.GetComponent<InputField>();
- phoneInput.onEndEdit.AddListener(OnPhoneInputEndEdit);
- codeInput = this.transform.Find("BackPanel/CodeInput").gameObject.GetComponent<InputField>();
- codeInput.onEndEdit.AddListener(OnCodeInputEndEdit);
- passInput = this.transform.Find("BackPanel/PassInput").gameObject.GetComponent<InputField>();
- passInput.onEndEdit.AddListener(OnPassInputEndEdit);
- passAginIput = this.transform.Find("BackPanel/PassAginInput").gameObject.GetComponent<InputField>();
- passAginIput.onEndEdit.AddListener(OnPassAginIputEndEdit);
- codeBtn = this.transform.Find("BackPanel/CodeButton").gameObject;
- EventTriggerListener.Get(codeBtn).onClick = OnCodeBtnClick;
- submitBtn = this.transform.Find("BackPanel/SubmitButton").gameObject;
- EventTriggerListener.Get(submitBtn).onClick = OnSubmitBtnClick;
- backButton = this.transform.Find("BackPanel/BackButton").gameObject;
- EventTriggerListener.Get(backButton).onClick = OnBackButtonClick;
- codeBtnText = this.transform.Find("BackPanel/CodeButton/Text").gameObject.GetComponent<Text>();
- }
- public override void Display(BaseUIForm _parent, Dictionary<string, string> data)
- {
- phoneInput.text = "";
- codeInput.text = "";
- passInput.text = "";
- passAginIput.text = "";
- errText.text = "";
- string action;
- data.TryGetValue("action", out action);
- switch (action)
- {
- case "getpass":
- data.TryGetValue("account", out editAccount);
- phoneInput.text = editAccount;
- break;
- }
- base.Display(_parent, data);
- }
- private bool IsGetCode
- {
- get
- {
- return isGetCode;
- }
- set
- {
- isGetCode = value;
- if (isGetCode)
- {
- EventTriggerListener.Get(codeBtn).onClick = null;
- codeBtn.transform.GetComponent<Button>().interactable = false;
- }
- else
- {
- EventTriggerListener.Get(codeBtn).onClick = OnCodeBtnClick;
- codeBtn.transform.GetComponent<Button>().interactable = true;
- codeBtnText.text = "获取验证码";
- }
- }
- }
- private void OnPhoneInputEndEdit(string phone)
- {
- editAccount = phone;
- errText.text = RegexInspection.AccountInspection(editAccount);
- }
- private void OnCodeInputEndEdit(string code)
- {
- editCode = code;
- errText.text = RegexInspection.CodeInspection(editCode);
- }
- private void OnPassInputEndEdit(string pass)
- {
- editPassWord = pass;
- errText.text = RegexInspection.PassWordInspection(editPassWord);
- }
- private void OnPassAginIputEndEdit(string passAgin)
- {
- editPassAgin = passAgin;
- if (string.IsNullOrEmpty(editPassWord))
- {
- return;
- }
- if (!editPassAgin.Equals(editPassWord))
- {
- errText.text = "两次输入密码不一致";
- }
- }
- private void OnCodeBtnClick(GameObject go)
- {
- //Dictionary<string, string> dataMsg = new Dictionary<string, string>();
- //dataMsg.Add("message", "验证码已发送!");
- //UIFormManager.GetInstance().ShowUIForm("MessagePanel", null, dataMsg);
- //return;
- errText.text = RegexInspection.AccountInspection(editAccount);
- if (!string.IsNullOrEmpty(errText.text))
- {
- return;
- }
- Dictionary<string, object> sendPostDic = new Dictionary<string, object>();
- string senStr;
- string[] code = new string[2];
- code[0] = editAccount;
- code[1] = "言灵世界";
- sendPostDic.Add("uid", "wanggangzero");
- sendPostDic.Add("ope", "604");
- sendPostDic.Add("cmd", "4002");
- sendPostDic.Add("paras", code);
- sendPostDic.Add("clientVer", "1.0.1");
- sendPostDic.Add("sign", "");
- senStr = MiniJSON.Json.Serialize(sendPostDic);
- StartCoroutine(UserManager.GetInstance().NetRequest(Config.api_url, senStr, CodeCallBack));
-
- }
- private void OnSubmitBtnClick(GameObject go)
- {
- errText.text = RegexInspection.AccountInspection(editAccount);
- if (!string.IsNullOrEmpty(errText.text))
- {
- return;
- }
- errText.text = RegexInspection.PassWordInspection(editPassWord);
- if (!string.IsNullOrEmpty(errText.text))
- {
- return;
- }
- if (!editPassAgin.Equals(editPassWord))
- {
- errText.text = "两次输入密码不一致";
- }
- if (!string.IsNullOrEmpty(errText.text))
- {
- return;
- }
- errText.text = RegexInspection.CodeInspection(editCode);
- if (!string.IsNullOrEmpty(errText.text))
- {
- return;
- }
- Dictionary<string, object> sendPostDic = new Dictionary<string, object>();
- string senStr;
- string[] code = new string[3];
- code[0] = editAccount;
- code[1] = RegexInspection.GetMD5Hash(editPassWord); ;
- code[2] = editCode;
- sendPostDic.Add("uid", "wanggangzero");
- sendPostDic.Add("ope", "600");
- sendPostDic.Add("cmd", "6007");
- sendPostDic.Add("paras", code);
- sendPostDic.Add("clientVer", "1.0.1");
- sendPostDic.Add("sign", "");
- senStr = MiniJSON.Json.Serialize(sendPostDic);
- StartCoroutine(UserManager.GetInstance().NetRequest(Config.api_url, senStr, SubmitCallBack));
- }
- private void OnBackButtonClick(GameObject go)
- {
- GoBackParent();
- }
- private void CodeCallBack(string code, string data)
- {
- if (code.Equals("succees"))
- {
- Dictionary<string, object> jsonMap = MiniJSON.Json.Deserialize(data) as Dictionary<string, object>;
- string errCode = jsonMap["err"].ToString();
- if (errCode.Equals("0"))
- {
- //succees----{ "uid":"wanggangzero","msgid":null,"err":0,"result":null,"ts":1527841566,"tag":{ },"sig":null}
- Dictionary<string, string> dataMsg = new Dictionary<string, string>();
- dataMsg.Add("message", "验证码已发送!");
- UIFormManager.GetInstance().ShowUIForm("MessagePanel",null, dataMsg);
- IsGetCode = true;
- getCodeTime = DateTime.Now;
- }
- else
- {
- IsGetCode = false;
- errText.text = (jsonMap["tag"] as Dictionary<string, object>)["errmsg"].ToString();
- }
- }
- else
- {
- IsGetCode = false;
- Debug.LogError("网络通信出错!---" + data);
- errText.text = "网络出错,请稍候再试!";
- }
- }
- private void SubmitCallBack(string code, string data)
- {
- if (code.Equals("succees"))
- {
- Dictionary<string, object> jsonMap = MiniJSON.Json.Deserialize(data) as Dictionary<string, object>;
- string errCode = jsonMap["err"].ToString();
- if (errCode.Equals("0"))
- {
- Dictionary<string, string> dataMsg = new Dictionary<string, string>();
- dataMsg.Add("message", "密码已修改!");
- UIFormManager.GetInstance().ShowUIForm("MessagePanel", null, dataMsg);
- //succees----{ "uid":"wanggangzero","msgid":null,"err":0,"result":null,"ts":1527841566,"tag":{ },"sig":null}
- TimeSpan toNow = DateTime.Now - new DateTime(1970, 1, 1);
- UserManager.GetInstance().SetSaveUserData(editAccount, RegexInspection.GetMD5Hash(editPassWord), ((int)toNow.TotalSeconds).ToString());
- Hiding();
- Dictionary<string, string> dataLogin = new Dictionary<string, string>();
- dataLogin.Add("action", "star");
- UIFormManager.GetInstance().ShowUIForm("LoginPanel", null, dataLogin);
-
- }
- else
- {
- errText.text = (jsonMap["tag"] as Dictionary<string, object>)["errmsg"].ToString();
- }
- }
- else
- {
- Debug.LogError("网络通信出错!---" + data);
- errText.text = "网络出错,请稍候再试!";
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (IsGetCode)
- {
- TimeSpan toNow = DateTime.Now - getCodeTime;
- int leftTime = reGetCodeTime - (int)toNow.TotalSeconds;
- if (leftTime > 0)
- {
- codeBtnText.text = "重新获取(" + leftTime + ")";
- }
- else
- {
- IsGetCode = false;
- }
- }
- }
- }
- }
|