黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
using System;
 
namespace Shared.Phone.UserCenter.Password
{
    /// <summary>
    /// 修改账号密码画面
    /// </summary>
    public class EditorAccountPasswordForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 密码错误信息控件
        /// </summary>
        private NormalViewControl msgControl = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设定标题
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uChangedPassword));
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameBackGroud = new FrameLayout();
            frameBackGroud.BackgroundColor = UserCenterColor.Current.White;
            frameBackGroud.Height = Application.GetRealHeight(521);
            bodyFrameLayout.AddChidren(frameBackGroud);
 
            //请输入原密码
            var rowOldPsw = new FrameRowControl();
            //关闭状态提示
            rowOldPsw.UseClickStatu = false;
            rowOldPsw.Y = Application.GetRealHeight(26);
            frameBackGroud.AddChidren(rowOldPsw);
            var txtoldPsw = new TextInputControl(Application.GetRealWidth(800), rowOldPsw.Height);
            txtoldPsw.X = ControlCommonResourse.XXLeft;
            txtoldPsw.SecureTextEntry = true;
            txtoldPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputOldPsw);
            rowOldPsw.AddChidren(txtoldPsw);
            //底线
            var btnOldLine = rowOldPsw.AddBottomLine();
            //联动线的状态
            txtoldPsw.btnLine = btnOldLine;
            //图标
            var btnoldPswIcon = rowOldPsw.AddMostRightEmptyIcon(58, 58);
            btnoldPswIcon.UnSelectedImagePath = "Item/HidenPWD.png";
            btnoldPswIcon.SelectedImagePath = "Item/UnHidenPWD.png";
            btnoldPswIcon.ButtonClickEvent += (sender, e) =>
            {
                btnoldPswIcon.IsSelected = !btnoldPswIcon.IsSelected;
                txtoldPsw.SecureTextEntry = !txtoldPsw.SecureTextEntry;
            };
 
            //忘记密码?
            var btnForgotPsw = new NormalViewControl(300, 49, true);
            btnForgotPsw.Y = rowOldPsw.Bottom + Application.GetRealHeight(23);
            btnForgotPsw.TextSize = 12;
            btnForgotPsw.TextColor = UserCenterColor.Current.TextOrangeColor;
            btnForgotPsw.TextID = R.MyInternationalizationString.ForgotPasswordMsg;
            btnForgotPsw.TextAlignment = TextAlignment.CenterRight;
            frameBackGroud.AddChidren(btnForgotPsw);
            btnForgotPsw.X = bodyFrameLayout.Width - ControlCommonResourse.XXLeft - btnForgotPsw.Width;
            btnForgotPsw.ButtonClickEvent += (sender, e) =>
            {
                var form = new ForgotAccountPasswordForm();
                form.AddForm();
            };
 
            //请输入新密码
            var rowNewPsw = new FrameRowControl();
            //关闭状态提示
            rowNewPsw.UseClickStatu = false;
            rowNewPsw.Y = Application.GetRealHeight(236);
            frameBackGroud.AddChidren(rowNewPsw);
            var txtNewPsw = new TextInputControl(Application.GetRealWidth(800), rowNewPsw.Height);
            txtNewPsw.X = ControlCommonResourse.XXLeft;
            txtNewPsw.SecureTextEntry = true;
            txtNewPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputNewPassword);
            rowNewPsw.AddChidren(txtNewPsw);
            //底线
            var btnNewLine = rowNewPsw.AddBottomLine();
            //联动线的状态
            txtNewPsw.btnLine = btnNewLine;
            //图标
            var btnNewPswIcon = rowNewPsw.AddMostRightEmptyIcon(58, 58);
            btnNewPswIcon.UnSelectedImagePath = "Item/HidenPWD.png";
            btnNewPswIcon.SelectedImagePath = "Item/UnHidenPWD.png";
            btnNewPswIcon.ButtonClickEvent += (sender, e) =>
            {
                btnNewPswIcon.IsSelected = !btnNewPswIcon.IsSelected;
                txtNewPsw.SecureTextEntry = !txtNewPsw.SecureTextEntry;
            };
 
            //请重复输入新密码
            var rowConfirmPsw = new FrameRowControl();
            //关闭状态提示
            rowConfirmPsw.UseClickStatu = false;
            rowConfirmPsw.Y = rowNewPsw.Bottom + Application.GetRealHeight(10);
            frameBackGroud.AddChidren(rowConfirmPsw);
            var txtConfirmPsw = new TextInputControl(Application.GetRealWidth(800), rowConfirmPsw.Height);
            txtConfirmPsw.X = ControlCommonResourse.XXLeft;
            txtConfirmPsw.SecureTextEntry = true;
            txtConfirmPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseRepeatInputNewPassword);
            rowConfirmPsw.AddChidren(txtConfirmPsw);
            //图标
            var btnConfirmPswIcon = rowConfirmPsw.AddMostRightEmptyIcon(58, 58);
            btnConfirmPswIcon.UnSelectedImagePath = "Item/HidenPWD.png";
            btnConfirmPswIcon.SelectedImagePath = "Item/UnHidenPWD.png";
            btnConfirmPswIcon.ButtonClickEvent += (sender, e) =>
            {
                btnConfirmPswIcon.IsSelected = !btnConfirmPswIcon.IsSelected;
                txtConfirmPsw.SecureTextEntry = !txtConfirmPsw.SecureTextEntry;
            };
 
            //错误信息
            this.msgControl = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(58), false);
            msgControl.Y = Application.GetRealHeight(582);
            msgControl.TextAlignment = TextAlignment.Center;
            msgControl.TextColor = 0xfff75858;
            msgControl.IsBold = true;
            bodyFrameLayout.AddChidren(msgControl);
 
            //确认修改
            var btnfinish = new BottomClickButton(688);
            btnfinish.Y = Application.GetRealHeight(708);
            btnfinish.TextID = R.MyInternationalizationString.DoEditor;
            bodyFrameLayout.AddChidren(btnfinish);
            btnfinish.ButtonClickEvent += (sender, e) =>
            {
                msgControl.Text = string.Empty;
                //密码检测
                bool flage = this.CheckPassword(txtoldPsw.Text, txtNewPsw.Text, txtConfirmPsw.Text);
                if (flage == false)
                {
                    return;
                }
                //保存密码
                this.SavePassword(txtConfirmPsw.Text);
            };
        }
 
        #endregion
 
        #region ■ 保存密码___________________________
 
        /// <summary>
        /// 保存密码
        /// </summary>
        /// <param name="newPassword"></param>
        private void SavePassword(string newPassword)
        {
            var pra = new SavePasswordPra();
            pra.NewPassword = newPassword;
 
            //更改密码
            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdatePassword", false, pra);
            if (flage == false)
            {
                return;
            }
            //密码已经修改,请重新登录
            string msg = Language.StringByID(R.MyInternationalizationString.uPasswordIsHadChangedAndLoginAgain);
            this.ShowMassage(ShowMsgType.Remind, msg, () =>
             {
                 //从新登录
                 UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
             }, Language.StringByID(R.MyInternationalizationString.Login));
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 密码检测
        /// </summary>
        /// <param name="oldPsw">输入的旧密码</param>
        /// <param name="newPsw">输入的新密码</param>
        /// <param name="newPsw2">输入的确认密码</param>
        /// <returns></returns>
        private bool CheckPassword(string oldPsw, string newPsw, string newPsw2)
        {
            if (oldPsw == string.Empty)
            {
                //请输入原密码
                this.msgControl.TextID = R.MyInternationalizationString.PleaseInputOldPsw;
                return false;
            }
            if (newPsw == string.Empty)
            {
                //请输入新密码
                this.msgControl.TextID = R.MyInternationalizationString.uPleaseInputNewPassword;
                return false;
            }
            if (newPsw2 == string.Empty)
            {
                //请重复输入新密码
                this.msgControl.TextID = R.MyInternationalizationString.uPleaseRepeatInputNewPassword;
                return false;
            }
            if (oldPsw != Common.Config.Instance.Password)
            {
                //密码错误,请重新输入
                this.msgControl.TextID = R.MyInternationalizationString.uOldPsswordIsError;
                return false;
            }
            if (newPsw != newPsw2)
            {
                //确认密码不一致,请重新输入
                this.msgControl.TextID = R.MyInternationalizationString.SecondPswNotEqual1;
                return false;
            }
            if (newPsw == oldPsw)
            {
                //新密码和原密码一致,请重新输入
                this.msgControl.TextID = R.MyInternationalizationString.uNewPswAndOldPswIsEqual;
                return false;
            }
            if (newPsw.Length < 6 || newPsw.Length > 13)
            {
                //密码长度为6-13个字符
                string textValue = Language.StringByID(R.MyInternationalizationString.PswLengthMsg);
                if (textValue.Contains("{0}") == true)
                {
                    textValue = string.Format(textValue, "6-13");
                }
                this.msgControl.Text = textValue;
                return false;
            }
 
            return true;
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 保存密码的启动参数类
        /// </summary>
        private class SavePasswordPra
        {
            /// <summary>
            /// 旧密码
            /// </summary>
            public string OldPassword = Common.Config.Instance.Password;
            /// <summary>
            /// 新密码
            /// </summary>
            public string NewPassword = string.Empty;
        }
 
        #endregion
    }
}