using System; using System.Threading.Tasks; namespace Shared.Phone.UserCenter.User { /// /// 验证新邮箱的画面 /// public class CheckNewEmailForm : UserCenterCommonForm { /// /// 重新发送的状态控件 /// private RowMostRightTextView btnStatu = null; /// /// 信息提示控件 /// private ViewNormalControl txtMsg = null; /// /// 下一步的控件 /// private BottomClickButton btnBottom = null; /// /// 线程运行 /// private bool IsAction = false; /// /// 新的邮箱 /// private string newEmail = string.Empty; /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// public void ShowForm() { //设定标题 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uCheckEmail)); //初始化中部控件 this.InitMiddleFrame(); } /// /// 初始化中部控件 /// private void InitMiddleFrame() { var rowlayout1 = new RowLayout(); rowlayout1.Height = ControlCommonResourse.ListViewRowHeight; bodyFrameLayout.AddChidren(rowlayout1); //新邮箱 var btnEmailView = new RowTopBlackView(false); btnEmailView.TextID = R.MyInternationalizationString.uNewEmail; rowlayout1.AddChidren(btnEmailView); //请输入邮箱 var txtEmail = new RowBottomEditorText(); txtEmail.Width = Application.GetRealWidth(770); txtEmail.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputEmail); txtEmail.PlaceholderTextColor = UserCenterColor.Current.TextTipColor; rowlayout1.AddChidren(txtEmail); var rowlayout2 = new RowLayout(); rowlayout2.Y = rowlayout1.Bottom; rowlayout2.Height = ControlCommonResourse.ListViewRowHeight; bodyFrameLayout.AddChidren(rowlayout2); //验证码 var btnCode = new RowTopBlackView(false); btnCode.TextID = R.MyInternationalizationString.uVerificationCode; rowlayout2.AddChidren(btnCode); //请输入验证码 var txtCode = new RowBottomEditorText(); txtCode.Width = Application.GetRealWidth(770); txtCode.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputVerificationCode); txtCode.PlaceholderTextColor = UserCenterColor.Current.TextTipColor; rowlayout2.AddChidren(txtCode); //状态 btnStatu = new RowMostRightTextView(); btnStatu.TextID = R.MyInternationalizationString.uSendVerificationCode; btnStatu.TextColor = UserCenterColor.Current.TextBlueColor; rowlayout2.AddChidren(btnStatu); btnStatu.ReSetYaxis(UViewAlignment.Bottom); //提示信息 txtMsg = new ViewNormalControl(800, true); txtMsg.X = ControlCommonResourse.XXLeft; txtMsg.Y = rowlayout2.Bottom + Application.GetRealHeight(5); txtMsg.TextColor = UserCenterColor.Current.Red; bodyFrameLayout.AddChidren(txtMsg); //验证 btnBottom = new BottomClickButton(); btnBottom.TextID = R.MyInternationalizationString.uVerification; btnBottom.Visible = false; bodyFrameLayout.AddChidren(btnBottom); btnBottom.MouseUpEvent += (sender, e) => { if (this.IsAction == false || txtCode.Text.Trim() == string.Empty) { txtMsg.TextID = R.MyInternationalizationString.uVerificationCodeError; return; } //验证验证码 this.CheckVerificationCode(txtCode.Text.Trim()); }; //发送验证码的单击事件 btnStatu.MouseUpEvent += (sender, e) => { string email = txtEmail.Text.Trim(); //检查邮箱 if (this.CheckEmail(email) == false) { return; } //发送验证码到邮箱 this.SendCodeToEmail(email); }; } /// /// 线程开启倒计时 /// private void StartTimeOutThead() { if (this.IsAction == true) { return; } this.IsAction = true; int waitime = 300; //重发 string repeat = Language.StringByID(R.MyInternationalizationString.RepeatSend1); new System.Threading.Thread(() => { while (this.IsAction == true) { if (waitime == 0) { break; } Application.RunOnMainThread(() => { this.btnStatu.Text = repeat + "(" + waitime + "s)"; }); waitime--; System.Threading.Thread.Sleep(1000); } this.IsAction = false; Application.RunOnMainThread(() => { //重新发送 this.btnStatu.Text = Language.StringByID(R.MyInternationalizationString.RepeatSend2); }); }) { IsBackground = true }.Start(); } /// /// 发送验证码到邮箱 /// private async void SendCodeToEmail(string Email) { var sendCodePra = new SendCodePra(); sendCodePra.Account = Email; bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/RegisterSendVerCode", sendCodePra); if (flage == false) { return; } this.newEmail = Email; Application.RunOnMainThread(() => { btnBottom.Visible = true; btnStatu.Text = Language.StringByID(R.MyInternationalizationString.RepeatSend1) + " (300s)"; }); //线程开启倒计时 this.StartTimeOutThead(); } /// /// 验证验证码 /// /// private async void CheckVerificationCode(string code) { var checkCodePra = new CheckCodePra(); checkCodePra.Code = code; checkCodePra.Account = newEmail; bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ValidatorCode", checkCodePra); if (flage == false) { Application.RunOnMainThread(() => { txtMsg.TextID = R.MyInternationalizationString.uVerificationCodeError; }); return; } this.IsAction = false; //变更邮箱 this.SaveNewEmail(); } /// /// 变更邮箱 /// private async void SaveNewEmail() { var pra = new SaveNewEmailPra(); pra.Account = this.newEmail; bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/BindAccount", pra); if (flage == false) { return; } //您的绑定邮箱已经更新 string msg = Language.StringByID(R.MyInternationalizationString.uYourEmailIsRefresh); this.ShowNormalMsg(msg, "RefreshUserInfoForm"); } /// /// 检查邮箱 /// /// /// private bool CheckEmail(string Email) { if (this.IsAction == true) { return false; } //输入为空 if (Email == string.Empty) { txtMsg.Text = Language.StringByID(R.MyInternationalizationString.uPleaseInputEmail); return false; } //检测邮箱格式 if (UserCenterLogic.CheckEmail(Email) == false) { txtMsg.Text = Language.StringByID(R.MyInternationalizationString.uThisIsNotEmailType); return false; } txtMsg.Text = string.Empty; return true; } /// /// 刷新个人信息画面 /// public void RefreshUserInfoForm() { //如果修改的是账号的话,则重新登录 if (UserCenterResourse.UserInfo.Email == Shared.Common.Config.Instance.Account) { UserCenterLogic.ReLoginAgain(this.newEmail); return; } UserCenterResourse.UserInfo.Email = this.newEmail; this.CloseForm(); } /// /// 画面关闭 /// /// 是否关闭界面,false的时候,只会调用关闭函数里面的附加功能 public override void CloseForm(bool isCloseForm = true) { this.IsAction = false; base.CloseForm(isCloseForm); } /// /// 发送验证码的启动参数 /// private class SendCodePra { /// /// 用户账号 /// public string Account = string.Empty; /// /// 公司编号,国内使用手机短信验证码时,此字段填入0,国外手机短信验证码,此字段填入4 /// public int Company = 0; /// /// 语言 /// public string Language = Shared.Language.CurrentLanguage; /// /// 国家地区代码,手机号发送验证码时使用 /// public int AreaCode = 0; } /// /// 发送验证码的启动参数 /// private class CheckCodePra { /// /// 用户账号 /// public string Account = string.Empty; /// /// 验证码 /// public string Code = "0"; /// /// 语言 /// public string Language = Shared.Language.CurrentLanguage; /// /// 国家地区代码,手机号发送验证码时使用 /// public int AreaCode = 0; } /// /// 保存新邮箱的启动参数 /// private class SaveNewEmailPra { /// /// 新用户账号 /// public string Account = string.Empty; } } }