xm
2019-07-16 b910cb79c9b5bcc204022a3cf9e6950f0a64dfbd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
 
namespace Shared.Phone.UserCenter.User
{
    /// <summary>
    /// 修改密码画面
    /// </summary>
    public class EditorPasswordForm : UserCenterCommonForm
    {
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设定标题
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uChangedPassword));
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        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());
            };
        }
 
        /// <summary>
        /// 保存密码
        /// </summary>
        /// <param name="newPassword"></param>
        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");
        }
 
        /// <summary>
        /// 从新登录
        /// </summary>
        public void ReLoginAgain()
        {
            UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
        }
 
        /// <summary>
        /// 密码检测
        /// </summary>
        /// <param name="txtMsg">信息提示控件</param>
        /// <param name="oldPsw">输入的旧密码</param>
        /// <param name="newPsw">输入的新密码</param>
        /// <param name="newPsw2">输入的确认密码</param>
        /// <returns></returns>
        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;
        }
 
        /// <summary>
        /// 保存密码的启动参数类
        /// </summary>
        private class SavePasswordPra
        {
            /// <summary>
            /// 旧密码
            /// </summary>
            public string OldPassword = Common.Config.Instance.Password;
            /// <summary>
            /// 新密码
            /// </summary>
            public string NewPassword = string.Empty;
        }
    }
}