using System; namespace Shared.Phone.UserCenter.User { /// /// 修改密码画面 /// public class EditorPasswordForm : UserCenterCommonForm { /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// public void ShowForm() { //设定标题 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uChangedPassword)); //初始化中部控件 this.InitMiddleFrame(); } /// /// 初始化中部控件 /// private void InitMiddleFrame() { //请输入原密码,再进入修改密码的步骤 var frameLayout = new FrameLayout() { Height = ControlCommonResourse.ListViewRowHeight }; bodyFrameLayout.AddChidren(frameLayout); var btnTitle = new ViewNormalControl(800, true); btnTitle.TextColor = UserCenterColor.Current.TextGrayColor; btnTitle.TextID = R.MyInternationalizationString.InputOldPswAndNext; btnTitle.Gravity = Gravity.CenterVertical; btnTitle.X = ControlCommonResourse.XXLeft; frameLayout.AddChidren(btnTitle); //请输入原密码 var rowLayout1 = new RowLayout(); rowLayout1.Height = ControlCommonResourse.ListViewRowHeight; rowLayout1.Y = btnTitle.Bottom; bodyFrameLayout.AddChidren(rowLayout1); var txtoldPsw = new RowPasswordControl(); rowLayout1.AddChidren(txtoldPsw); txtoldPsw.Init(Language.StringByID(R.MyInternationalizationString.PleaseInputOldPsw)); //忘记密码? var btnForgotPsw = new ViewNormalControl(800, true); btnForgotPsw.TextColor = UserCenterColor.Current.TextBlueColor; btnForgotPsw.TextID = R.MyInternationalizationString.ForgotPasswordMsg; btnForgotPsw.Y = rowLayout1.Bottom + Application.GetRealHeight(10); btnForgotPsw.X = ControlCommonResourse.XXLeft; bodyFrameLayout.AddChidren(btnForgotPsw); btnForgotPsw.MouseUpEventHandler += (sender, e) => { var form = new ForgotPasswordMenuForm(); this.AddForm(form); }; //请输入新密码 var rowLayout2 = new RowLayout(); rowLayout2.Height = ControlCommonResourse.ListViewRowHeight; rowLayout2.Y = btnForgotPsw.Bottom; bodyFrameLayout.AddChidren(rowLayout2); var txtNewPsw = new RowPasswordControl(); rowLayout2.AddChidren(txtNewPsw); txtNewPsw.Init(Language.StringByID(R.MyInternationalizationString.uPleaseInputNewPassword)); //确认新密码 var rowLayout3 = new RowLayout(); rowLayout3.Height = ControlCommonResourse.ListViewRowHeight; rowLayout3.Y = rowLayout2.Bottom; bodyFrameLayout.AddChidren(rowLayout3); var txtConfirmPsw = new RowPasswordControl(); rowLayout3.AddChidren(txtConfirmPsw); txtConfirmPsw.Init(Language.StringByID(R.MyInternationalizationString.uConfirmNewPassword)); var txtMsg = new ViewNormalControl(800, true); txtMsg.X = ControlCommonResourse.XXLeft; txtMsg.Y = rowLayout3.Bottom + Application.GetRealHeight(5); txtMsg.TextColor = UserCenterColor.Current.Red; bodyFrameLayout.AddChidren(txtMsg); //完成 var btnfinish = new TopLayoutFinshView(); topFrameLayout.AddChidren(btnfinish); btnfinish.MouseUpEventHandler += (sender, e) => { //密码检测 bool flage = this.CheckPassword(txtMsg, txtoldPsw.Text.Trim(), txtNewPsw.Text.Trim(), txtConfirmPsw.Text.Trim()); if (flage == false) { return; } //保存密码 this.SavePassword(txtNewPsw.Text.Trim()); }; } /// /// 保存密码 /// /// private async void SavePassword(string newPassword) { var pra = new SavePasswordPra(); pra.NewPassword = newPassword; //更改密码 bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdatePassword", pra); if (flage == false) { return; } //密码已经修改,请重新登录 string msg = Language.StringByID(R.MyInternationalizationString.uPasswordIsHadChangedAndLoginAgain); this.ShowNormalMsg(msg, "ReLoginAgain"); } /// /// 从新登录 /// public void ReLoginAgain() { UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account); } /// /// 密码检测 /// /// 信息提示控件 /// 输入的旧密码 /// 输入的新密码 /// 输入的确认密码 /// private bool CheckPassword(ViewNormalControl txtMsg, string oldPsw, string newPsw, string newPsw2) { txtMsg.Text = string.Empty; if (oldPsw == string.Empty) { //请输入原密码 txtMsg.TextID = R.MyInternationalizationString.PleaseInputOldPsw; return false; } if (newPsw == string.Empty) { //请输入新密码 txtMsg.TextID = R.MyInternationalizationString.uPleaseInputNewPassword; return false; } if (newPsw2 == string.Empty) { //请输入确认密码 txtMsg.TextID = R.MyInternationalizationString.PleaseInputConfirmPsw; return false; } if (oldPsw != Common.Config.Instance.Password) { //原密码输入不一致 txtMsg.TextID = R.MyInternationalizationString.uOldPsswordIsError; return false; } if (newPsw.Length < UserCenterResourse.PasswordLength) { //密码长度不低于{0}位数 txtMsg.Text = string.Format(Language.StringByID(R.MyInternationalizationString.PswLengthMsg), UserCenterResourse.PasswordLength); return false; } if (newPsw != newPsw2) { //两次输入的密码不一致 txtMsg.TextID = R.MyInternationalizationString.SecondPswNotEqual; return false; } if (newPsw == oldPsw) { //新密码和原密码一致 txtMsg.TextID = R.MyInternationalizationString.SecondPswNotEqual; return false; } return true; } /// /// 保存密码的启动参数类 /// private class SavePasswordPra { /// /// 旧密码 /// public string OldPassword = Common.Config.Instance.Password; /// /// 新密码 /// public string NewPassword = string.Empty; } } }