using System; using Shared.Common; using System.Text.RegularExpressions; namespace Shared.Phone.Device.Account { public class ForgotPasswordSetNewPWD:FrameLayout { public ForgotPasswordSetNewPWD() { BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; } /// /// 重置密码 areaCode在邮箱中不需要 /// /// Account. /// Phone or email. /// Area code. public void Show(string account ,string phoneOrEmail, string areaCode = "") { ShowSetNewPWD(account,phoneOrEmail,areaCode); } void ShowSetNewPWD(string account, string phoneOrEmail,string areaCode="") { #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(); }; #endregion #region --midFL-- var midFL = new FrameLayout() { Y = topView.Bottom, Height = Application.GetRealHeight(1920 - 220), BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, }; AddChidren(midFL); var passwordFL = new FrameLayout() { Y = Application.GetRealHeight(100), Height = Application.GetRealHeight(100) }; midFL.AddChidren(passwordFL); var password = new EditText() { X = Application.GetRealWidth(CommonPage.XLeft), Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(100)-1, TextAlignment = TextAlignment.CenterLeft, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.InputNewPWD), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, SecureTextEntry = true }; passwordFL.AddChidren(password); var hidenPWDbtn = new Button() { X = passwordFL.Width - Application.GetRealWidth(CommonPage.XLeft+100), Width = Application.GetMinRealAverage(72), Height = Application.GetMinRealAverage(72), Gravity=Gravity.CenterVertical, UnSelectedImagePath = "Account/HidenPWD.png", SelectedImagePath = "Account/UnHidenPWD.png" }; passwordFL.AddChidren(hidenPWDbtn); var accountLine = new FrameLayout() { Y = Application.GetRealHeight(100)-1, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor }; passwordFL.AddChidren(accountLine); var passwordConfirmFL = new FrameLayout() { Y = passwordFL.Bottom + Application.GetRealHeight(100), Height = Application.GetRealHeight(100) }; midFL.AddChidren(passwordConfirmFL); var passwordConfirm = new EditText() { X = Application.GetRealWidth(CommonPage.XLeft), Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(100) - 1, TextAlignment = TextAlignment.CenterLeft, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseConfirmNewPassword), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, SecureTextEntry = true }; passwordConfirmFL.AddChidren(passwordConfirm); var hidenPWDComfirmbtn = new Button() { X = passwordFL.Width - Application.GetRealWidth(CommonPage.XLeft+100), Width = Application.GetMinRealAverage(72), Height = Application.GetMinRealAverage(72), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Account/HidenPWD.png", SelectedImagePath = "Account/UnHidenPWD.png" }; passwordConfirmFL.AddChidren(hidenPWDComfirmbtn); var passwordConfirmLine = new FrameLayout() { Y = Application.GetRealHeight(100)-1, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor }; passwordConfirmFL.AddChidren(passwordConfirmLine); 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); FrameLayout pwdStrengthFL = new FrameLayout() { Y = passwordFL.Bottom + Application.GetRealHeight(10), Height = Application.GetRealHeight(60), }; #endregion #region event FrameLayout addPWDStrengthFL() { passwordConfirmFL.Y = pwdStrengthFL.Bottom; var pwdLength = new Button() { X = Application.GetRealWidth(100), Height = Application.GetRealHeight(60), TextID = R.MyInternationalizationString.YourPWDIsTooSample, TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextAlignment = TextAlignment.CenterLeft, SelectedTextColor = ZigbeeColor.Current.GXCTextBlackColor }; pwdStrengthFL.AddChidren(pwdLength); return pwdStrengthFL; }; /// ///密码为 数字递增 /// /// true, if number add was pwded, false otherwise. /// Pwd. bool pwdNumAdd(string pwd) { if (pwd.Length < 6) return true; for (int i = 1; i < pwd.Length-1;i++) { if(pwd[i]!=pwd[i+1]-1) return false; } return true; } /// /// 密码为同一字符 /// /// true, if same was pwded, false otherwise. /// Pwd. bool pwdSame(string pwd) { if (pwd.Length < 6) return true; for (int i = 1; i < pwd.Length - 1; i++) { if (pwd[i] != pwd[i + 1]) return false; } return true; } password.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; if (pwdNumAdd(password.Text.Trim()) || pwdSame(password.Text.Trim())) { midFL.AddChidren(addPWDStrengthFL()); passwordConfirmFL.Y = addPWDStrengthFL().Bottom + Application.GetRealHeight(50); } else { addPWDStrengthFL().RemoveFromParent(); passwordConfirmFL.Y = passwordFL.Bottom + Application.GetRealHeight(100); } if (passwordConfirm.Text.Trim().Length >= 6 && passwordConfirm.Text.Trim().Length <= 16 && password.Text.Trim().Length >= 6 && password.Text.Trim().Length <= 16) { resetPWDBtn.Enable = resetPWDBtn.IsSelected = true; } else if(password.Text.Trim().Length>16) { password.Text = e.Remove(16); } else { resetPWDBtn.Enable = resetPWDBtn.IsSelected = false; } }; password.FoucsChanged += (sender, e) => { addPWDStrengthFL().RemoveFromParent(); passwordConfirmFL.Y = passwordFL.Bottom + Application.GetRealHeight(100); }; passwordConfirm.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; if (passwordConfirm.Text.Trim().Length >= 6 && passwordConfirm.Text.Trim().Length<=16 && password.Text.Trim().Length >= 6 && password.Text.Trim().Length <= 16) { resetPWDBtn.Enable = resetPWDBtn.IsSelected = true; } else if(passwordConfirm.Text.Trim().Length>16) { passwordConfirm.Text = e.Remove(16); } else { resetPWDBtn.Enable = resetPWDBtn.IsSelected = false; } }; hidenPWDbtn.MouseUpEventHandler += (sender, e) => { password.SecureTextEntry = !password.SecureTextEntry; hidenPWDbtn.IsSelected = !hidenPWDbtn.IsSelected; }; hidenPWDComfirmbtn.MouseUpEventHandler += (sender, e) => { hidenPWDComfirmbtn.IsSelected = !hidenPWDComfirmbtn.IsSelected; passwordConfirm.SecureTextEntry = !passwordConfirm.SecureTextEntry; }; resetPWDBtn.MouseUpEventHandler += async (sender, e) => { //先判断2次密码输入是否一致 if (password.Text.Trim() != passwordConfirm.Text.Trim()) { var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.TwoPasswordInconsistency), Language.StringByID(R.MyInternationalizationString.Confrim)); alert.Show(); password.Text = ""; passwordConfirm.Text = ""; return; } CommonPage.Loading.Start(); string passwordText = password.Text.Trim(); try { string requestJson; if (areaCode=="") { var reqDto = new SendDataToServer.ResetPasswordObj() { Account = account, Password = password.Text, AgainPassword = passwordConfirm.Text }; requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto); } else { var reqDto = new SendDataToServer.ResetPasswordObj() { Account = account, Password = password.Text.Trim(), AreaCode=int.Parse(areaCode), AgainPassword = passwordConfirm.Text.Trim() }; requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto); } var revertObj =await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/ResetPassword", System.Text.Encoding.UTF8.GetBytes(requestJson)); if(revertObj==null) { CommonPage.Instance.FailureToServer(); return; } var stateCodeStr = revertObj.StateCode.ToUpper(); if (stateCodeStr == "SUCCESS") { var forgetWPDSuccessDialog = new Dialog(); forgetWPDSuccessDialog.Show(); var forgetSuccessView = new FrameLayout() { BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, Gravity = Gravity.Center, Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(550), Radius =(uint)Application.GetRealHeight(30) }; forgetWPDSuccessDialog.AddChidren(forgetSuccessView); var forgetSuccessTip = new Button() { Y = Application.GetRealHeight(50), Height = Application.GetRealHeight(100), TextID = R.MyInternationalizationString.TIP, TextColor = ZigbeeColor.Current.GXCTextBlackColor, TextAlignment = TextAlignment.Center, TextSize = 18, Gravity = Gravity.CenterHorizontal }; forgetSuccessView.AddChidren(forgetSuccessTip); var forgetSuccessContents = new Button() { Y = Application.GetRealHeight(50) + forgetSuccessTip.Bottom, Height = Application.GetRealHeight(100), TextID = R.MyInternationalizationString.ResetPWDSuccessPleaseLoginAgain, TextColor = ZigbeeColor.Current.GXCTextBlackColor, TextAlignment = TextAlignment.Center, Gravity = Gravity.CenterHorizontal }; forgetSuccessView.AddChidren(forgetSuccessContents); var confirmBtn = new Button() { Y = Application.GetRealHeight(100) + forgetSuccessContents.Bottom, Width = Application.GetRealWidth(300), Height = Application.GetRealHeight(100), TextID = R.MyInternationalizationString.Confrim, TextColor = ZigbeeColor.Current.GXCTextWhiteColor, TextAlignment = TextAlignment.Center, TextSize = 18, BackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor, Gravity = Gravity.CenterHorizontal, Radius =(uint)Application.GetRealHeight(50) }; forgetSuccessView.AddChidren(confirmBtn); //重置密码成功回到登录界面 confirmBtn.MouseUpEventHandler += (sender1, e1) => { forgetWPDSuccessDialog.Close(); this.RemoveFromParent(); Shared.Common.CommonPage.Instance.RemoveViewByTag("Forgot"); var login = new AccountLogin(); Shared.Common.CommonPage.Instance.AddChidren(login); login.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 if(stateCodeStr == "FAIL") { //操作失败 loginErrorBtn.TextID = R.MyInternationalizationString.FAIL; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FAIL); } else { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed); } } catch { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; } finally { CommonPage.Loading.Hide(); } }; #endregion } } }