using System; using Shared.Common; using System.Timers; using System.Text.RegularExpressions; namespace Shared.Phone.Device.Account { public class ForgotPasswordByEmail:FrameLayout { public ForgotPasswordByEmail() { BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; Tag = "Forgot"; } public void Show() { ShowForgotPWD(); } void ShowForgotPWD() { var t = new Timer(); var dateBegin = new DateTime(); #region --topview-- var topBGView = new FrameLayout() { Height = Application.GetRealHeight(220), BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor }; AddChidren(topBGView); var topView = new FrameLayout() { Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y), Height = Application.GetRealHeight(220 - CommonPage.NavigationTitle_Y), BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor, }; AddChidren(topView); var titleName = new Button() { TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.ForgotPassword, TextSize = 19, TextColor = ZigbeeColor.Current.GXCTextBlackColor, Width=Application.GetRealWidth(600), Gravity=Gravity.CenterHorizontal }; topView.AddChidren(titleName); var back = new Button() { X = Application.GetRealWidth(CommonPage.Navigation_X), Height = Application.GetMinRealAverage(110), Width = Application.GetMinRealAverage(110), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", Gravity = Gravity.CenterVertical }; topView.AddChidren(back); back.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); var login = new AccountLogin(); Shared.Common.CommonPage.Instance.AddChidren(login); login.Show(); }; #endregion #region --midFL-- var midFL = new FrameLayout() { Y = topView.Bottom, Height = Application.GetRealHeight(1920 - 220), BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, }; AddChidren(midFL); var accountTIPS = new Button() { Width = Application.GetRealWidth(1080 - CommonPage.XLeft * 2), Height = Application.GetRealHeight(100), TextAlignment = TextAlignment.CenterLeft, Gravity = Gravity.CenterHorizontal, TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextID = R.MyInternationalizationString.PleaseInputTheEmailAndYouWillHaveVerificatoinCode }; midFL.AddChidren(accountTIPS); var accountFL = new FrameLayout() { Y = accountTIPS.Bottom + Application.GetRealHeight(100), Height = Application.GetRealHeight(100) }; midFL.AddChidren(accountFL); var accountET = new EditText() { X = Application.GetRealWidth(CommonPage.XLeft), Width = Application.GetRealWidth(800), Height = Application.GetRealHeight(100)-1, Gravity=Gravity.CenterVertical, TextAlignment = TextAlignment.CenterLeft, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputEmail), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor }; accountFL.AddChidren(accountET); var accountLine = new FrameLayout() { Y = Application.GetRealHeight(100)-1, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor }; accountFL.AddChidren(accountLine); var verificationCodeFL = new FrameLayout() { Y = accountFL.Bottom + Application.GetRealHeight(100), Height = Application.GetRealHeight(100) }; midFL.AddChidren(verificationCodeFL); var verificationCodeET = new EditText() { X = Application.GetRealWidth(CommonPage.XLeft), Width = Application.GetRealWidth(500), Height = Application.GetRealHeight(100) - 1, TextAlignment = TextAlignment.CenterLeft, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputVerificationCode), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor }; verificationCodeFL.AddChidren(verificationCodeET); var verificationCodeLine = new FrameLayout() { Y = Application.GetRealHeight(100) - 1, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor }; verificationCodeFL.AddChidren(verificationCodeLine); var sendCodeBtn = new Button() { X = Application.GetRealWidth(1080 - 400 - CommonPage.XLeft), Width = Application.GetRealWidth(400), Y = Application.GetRealHeight(100) + verificationCodeFL.Bottom, Height = Application.GetRealHeight(100), TextID = R.MyInternationalizationString.SendVerificationCode, TextColor = ZigbeeColor.Current.GXCButtonUnselectedColor, SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor, TextAlignment = TextAlignment.CenterRight, Enable = false, IsSelected = false, }; midFL.AddChidren(sendCodeBtn); var resetPWDBtn = new Button() { Width = Application.GetRealWidth(700), Y = Application.GetRealHeight(1920 - 220 - 400), Height = Application.GetRealHeight(110), Radius = (uint)Application.GetRealHeight(55), TextID = R.MyInternationalizationString.ResetPWD, TextColor = ZigbeeColor.Current.GXCTextWhiteColor, TextAlignment = TextAlignment.Center, TextSize = 15, BackgroundColor = ZigbeeColor.Current.GXCButtonUnselectedColor, SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor, Gravity = Gravity.CenterHorizontal, Enable = false, IsSelected = false }; midFL.AddChidren(resetPWDBtn); //错误提示Btn var loginErrorBtn = new Button() { Y = resetPWDBtn.Bottom + Application.GetRealHeight(50), Width = Application.GetRealWidth(1080 - 100), Height = Application.GetRealHeight(110), TextColor = ZigbeeColor.Current.GXCRedColor, Gravity = Gravity.CenterHorizontal }; midFL.AddChidren(loginErrorBtn); #endregion #region --event-- accountET.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; if (accountET.Text.Trim().Length>0) { sendCodeBtn.Enable = sendCodeBtn.IsSelected = true; } else { sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; } }; verificationCodeET.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; if (verificationCodeET.Text.Trim().Length > 0) { resetPWDBtn.Enable = resetPWDBtn.IsSelected = true; } else { resetPWDBtn.Enable = resetPWDBtn.IsSelected = false; } }; sendCodeBtn.MouseUpEventHandler += async (sender, e) => { var reg = new Regex(CommonPage.EmailRegexStr); var ss = reg.Match(accountET.Text.Trim()); //校验邮箱 if (!ss.Success) { var aler = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.PleaseInputTheCorrectEmail), Language.StringByID(R.MyInternationalizationString.Confrim)); aler.Show(); accountET.Text = ""; } else { string phoneNum = accountET.Text.Trim(); CommonPage.Loading.Start(); try { var reqDtoSignPhone = new SendDataToServer.LoginSendVerCodeObj() { Account = phoneNum, Company = 0, AreaCode = 0, Language = CommonPage.ZigBeeLanguage }; var requesetJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDtoSignPhone); var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/LoginSendVerCode", System.Text.Encoding.UTF8.GetBytes(requesetJson)); if (requestRevertObj == null) { CommonPage.Instance.FailureToServer(); return; } var stateCodeStr = requestRevertObj.StateCode.ToUpper(); if (stateCodeStr == "SUCCESS") { TimeBegin(); var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SendVerificationCodeSuccess), Language.StringByID(R.MyInternationalizationString.Confrim)); alert.Show(); } else if (stateCodeStr == "PARAMETEROREMPTY") { //提供的参数错误 loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY); } else if (stateCodeStr == "ACCOUNTNOEXISTS") { //账号不存在 loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ACCOUNTNOEXISTS); } else { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed); } } catch { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; } finally { CommonPage.Loading.Hide(); } } }; resetPWDBtn.MouseUpEventHandler += async (sender, e) => { var vCode = verificationCodeET.Text.Trim(); var vPhone = accountET.Text.Trim(); CommonPage.Loading.Start(); try { var reqDto = new SendDataToServer.ValidatorCodeObj() { Account = vPhone, Code = int.Parse(vCode), AreaCode = 0, Language = CommonPage.ZigBeeLanguage }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto); //验证验证码 var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/ValidatorCode", System.Text.Encoding.UTF8.GetBytes(requestJson)); if (requestRevertObj == null) { CommonPage.Instance.FailureToServer(); return; } var stateCodeStr = requestRevertObj.StateCode.ToUpper(); if (stateCodeStr == "SUCCESS") { ModifyPWD(vPhone); } else if (stateCodeStr == "VALIDCODEANDPHONENOEQUAL") { //验证码错误 loginErrorBtn.TextID = R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL); } else if (stateCodeStr == "SENDFAIL") { //验证码发送失败 loginErrorBtn.TextID = R.MyInternationalizationString.SENDFAIL; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.SENDFAIL); } else if (stateCodeStr == "ACCOUNTNOEXISTS") { //账号不存在 loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ACCOUNTNOEXISTS); } else if (stateCodeStr == "PARAMETEROREMPTY") { //提供的参数错误 loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY); } else { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed); } } catch { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; } finally { CommonPage.Loading.Hide(); } }; void ModifyPWD(string account) { var newPWD = new ForgotPasswordSetNewPWD(); AddChidren(newPWD); newPWD.Show(account,"email"); } void TimeBegin() { t.Interval = 1000; t.AutoReset = true; t.Enabled = true; t.Elapsed += new ElapsedEventHandler(TimeOut); //启动计时器倒计时-60s t.Start(); dateBegin = DateTime.Now; } void TimeOut(object source, System.Timers.ElapsedEventArgs e) { var span = DateTime.Now - dateBegin; if (span.TotalSeconds <= 61) { Application.RunOnMainThread(() => { sendCodeBtn.Text = Convert.ToInt16((60 - span.TotalSeconds)) + "s" + Language.StringByID(R.MyInternationalizationString.SendVerificationCode); sendCodeBtn.Enable = false; }); } else { Application.RunOnMainThread(() => { sendCodeBtn.Enable = true; sendCodeBtn.TextID = R.MyInternationalizationString.SendVerificationCode; t.Stop(); t.Close(); }); } } #endregion } } }