using System; using System.Text.RegularExpressions; namespace Shared.SimpleControl.Phone { public class ForgotPassword : Dialog { PageLayout bodyPageView; /// /// 构造函数 /// public ForgotPassword () { BackgroundColor = SkinStyle.Current.MainColor; ForgotPasswordShow (); } void ForgotPasswordShow () { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = "Forgot password?", TextSize = 19, TextColor = SkinStyle.Current.TextColor1 }; topView.AddChidren (title); //var logo = new Button () { // Width = Application.GetRealWidth (154), // Height = Application.GetRealHeight (90), // X = Application.GetRealWidth (486), // UnSelectedImagePath = MainPage.LogoString, // Gravity = Gravity.CenterVertical, //}; //topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", //SelectedImagePath = "Item/BackSelected.png", Gravity = Gravity.CenterVertical, }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { new AccountLogin ().Show (); Close (); }; #endregion bodyPageView = new PageLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126), Y = topView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor, }; AddChidren (bodyPageView); bodyPageView.PageChange += (sender, e) => { //2020-09-04 修复安卓右滑闪退问题 if (e < bodyPageView.ChildrenCount - 1) { bodyPageView.GetChildren (bodyPageView.ChildrenCount - 1).RemoveFromParent (); } }; FrameLayout bodyView = new FrameLayout (); bodyPageView.AddChidren (bodyView); bodyPageView.IsShowPoint = false; EmailForgotView (bodyView); } /// /// 邮箱忘记密码页面 /// /// void EmailForgotView (FrameLayout registrationView) { registrationView.RemoveAll (); Button btnEmail = new Button () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = Application.GetRealWidth (20), TextID = R.MyInternationalizationString.EmailAddress, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, TextColor = SkinStyle.Current.TextColor1, }; registrationView.AddChidren (btnEmail); FrameLayout EmailView = new FrameLayout () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = btnEmail.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, //Text = "1270166900@qq.com" }; registrationView.AddChidren (EmailView); EditText etEmailAddress = new EditText () { TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, PlaceholderText = Language.StringByID (R.MyInternationalizationString.EmailAddress), PlaceholderTextColor = SkinStyle.Current.PlaceholderTextColor, }; EmailView.AddChidren (etEmailAddress); Button btnNext = new Button () { Y = EmailView.Bottom + Application.GetRealWidth (20), Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.Send, TextColor = SkinStyle.Current.TextColor1, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, TextSize = 18, TextAlignment = TextAlignment.Center, //IsSelected = true }; registrationView.AddChidren (btnNext); btnNext.MouseDownEventHandler += (sender, e) => { btnNext.IsSelected = true; }; btnNext.MouseUpEventHandler += (sender, e) => { btnNext.IsSelected = false; string account = etEmailAddress.Text.Trim (); if (!CommonUtlis.Current.CheckEmail (account)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseCheckEmailAddressCorrectly), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } // SendVerificationCode (account, false); }; } /// /// 手机或者邮箱发送验证码并加载对应的 忘记密码页面 /// /// 账号 邮箱或者手机号 /// 是否是手机 void SendVerificationCode (string account, bool isPhone = true) { MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestRevertObj = HttpServerRequest.Current.VerificationCodeSend (VerifyType.FIND_PASSWORD, account); if (requestRevertObj.Code.ToUpper () == StateCode.SUCCESS) { Application.RunOnMainThread (() => { InitSMSView (account, false); bodyPageView.PageIndex = bodyPageView.ChildrenCount - 1; }); } else { //提示错误 IMessageCommon.Current.ShowErrorInfoAlter (requestRevertObj.Code); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } /// /// 验证验证码并提交注册 /// /// /// void InitSMSView (string mAccount, bool bPhone = true) { FrameLayout mobileChencView = new FrameLayout (); bodyPageView.AddChidren (mobileChencView); Button btnAccount = new Button () { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (20), Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (50), Text = mAccount, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.Center, }; mobileChencView.AddChidren (btnAccount); Button btnPassword = new Button () { Gravity = Gravity.CenterHorizontal, Y = btnAccount.Bottom, Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), TextID = R.MyInternationalizationString.Password, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, }; mobileChencView.AddChidren (btnPassword); EditText etPassword = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = btnPassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, SecureTextEntry = true, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1 //Text = "1270166900@qq.com" }; mobileChencView.AddChidren (etPassword); Button btnConfrimPassword = new Button () { Gravity = Gravity.CenterHorizontal, Y = etPassword.Bottom, Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), TextID = R.MyInternationalizationString.ConfirmPassword, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, }; mobileChencView.AddChidren (btnConfrimPassword); EditText etConfrimPassword = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = btnConfrimPassword.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, SecureTextEntry = true, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1 }; mobileChencView.AddChidren (etConfrimPassword); Button btnTitle = new Button () { Gravity = Gravity.CenterHorizontal, Y = etConfrimPassword.Bottom, Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), TextID = R.MyInternationalizationString.MobileVerificationCode, TextColor = SkinStyle.Current.TextColor1, TextAlignment = TextAlignment.CenterLeft, }; mobileChencView.AddChidren (btnTitle); EditText etCode = new EditText () { Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, Y = btnTitle.Bottom, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1 }; mobileChencView.AddChidren (etCode); Button btnConfirem = new Button () { Y = etCode.Bottom + Application.GetRealWidth (50), Width = Application.GetRealWidth (500), Height = Application.GetRealWidth (85), Gravity = Gravity.CenterHorizontal, BackgroundColor = SkinStyle.Current.MainColor, SelectedBackgroundColor = SkinStyle.Current.SelectedColor, TextID = R.MyInternationalizationString.Confrim, TextColor = SkinStyle.Current.TextColor1, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, TextSize = 18, TextAlignment = TextAlignment.Center, }; mobileChencView.AddChidren (btnConfirem); etCode.TextChangeEventHandler += (sender, e) => { if (e.Length > 6) { etCode.Text = e.Remove (6); } else if (e.Length == 6) { //btnConfirem.IsSelected = btnConfirem.Enable = true; } else { //btnConfirem.IsSelected = btnConfirem.Enable = false; } }; btnConfirem.MouseDownEventHandler += (sender, e) => { btnConfirem.IsSelected = true; }; btnConfirem.MouseUpEventHandler += (sender, e) => { btnConfirem.IsSelected = false; string passwordText = etPassword.Text.Trim (); string confrimPasswordText = etConfrimPassword.Text.Trim (); //检测密码 if (passwordText == "" && confrimPasswordText == "") { new Alert ("", Language.StringByID (R.MyInternationalizationString.PleaseWriteTheCompleteContent), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } else if (!CommonUtlis.Current.CheckPassword (passwordText)) { new Alert ("", ErrorCode.PasswordStrengthNotMatch, Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } else if (passwordText != confrimPasswordText) { new Alert ("", Language.StringByID (R.MyInternationalizationString.RepeatPasswordsDidNotmatch), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } //检测验证码 string verCode = etCode.Text.Trim (); if (string.IsNullOrEmpty (verCode)) { Utlis.ShowTip (Language.StringByID (R.MyInternationalizationString.PlsEntryVerificationCode)); return; } MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { try { var requestObj = HttpServerRequest.Current.ForgetPassword (mAccount, passwordText, verCode, bPhone); if (requestObj.Code == StateCode.SUCCESS) { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PasswordModificationSuccess), Language.StringByID (R.MyInternationalizationString.Close)).Show (); Close (); new AccountLogin (mAccount, passwordText).Show (); }); } else { //提示错误 IMessageCommon.Current.ShowErrorInfoAlter (requestObj.Code); } } catch { MainPage.FailureToServer (); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; } } }