黄学彪
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter.Password
{
    /// <summary>
    /// 忘记二次验证的密码界面
    /// </summary>
    public class ForgotSecondaryPasswordForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 标记是否能够校验验证码了
        /// </summary>
        private bool canCheckCode = false;
        /// <summary>
        /// 手机或者邮箱
        /// </summary>
        private string strPhoneEmail = string.Empty;
        /// <summary>
        /// 错误信息控件
        /// </summary>
        private NormalViewControl btnMsgControl = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ForgotPassword));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(323);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
 
            var rowPhone = new FrameRowControl();
            //右边偏移量->增加宽度
            rowPhone.RightOffset = -ControlCommonResourse.XXLeft;
            rowPhone.Y = Application.GetRealHeight(23);
            rowPhone.Width = this.GetPictrueRealSize(628);
            bodyFrameLayout.AddChidren(rowPhone);
            //请输入邮箱或手机号
            string phoneValue = string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true ? string.Empty : "+" + UserCenterResourse.UserInfo.AreaCode + " " + UserCenterResourse.UserInfo.Phone;
            var txtPhone = rowPhone.AddLeftCaption(string.IsNullOrEmpty(phoneValue) == true ? UserCenterResourse.UserInfo.Email : phoneValue, 600);
            txtPhone.TextColor = UserCenterColor.Current.TextGrayColor2;
            //底线
            rowPhone.AddBottomLine();
            //当前选择的方式
            this.strPhoneEmail = txtPhone.Text;
 
            var rowCode = new FrameRowControl();
            rowCode.Y = rowPhone.Bottom + Application.GetRealHeight(20);
            rowCode.Width = this.GetPictrueRealSize(628);
            bodyFrameLayout.AddChidren(rowCode);
            //请输入验证码
            var txtCode = rowCode.AddLeftInput("", 600);
            txtCode.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputVerificationCode);
            txtCode.TextChangeEventHandler += this.txtCodeValueChangedEvent;
 
            //获取验证码
            var btnCode = new NormalViewControl(302, 127, true);
            btnCode.X = rowPhone.Right + Application.GetRealWidth(35);
            btnCode.Y = Application.GetRealHeight(23);
            btnCode.RadiusEx = 12;
            btnCode.TextID = R.MyInternationalizationString.uGetVerificationCode;
            btnCode.TextColor = UserCenterColor.Current.White;
            btnCode.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            btnCode.TextAlignment = TextAlignment.Center;
            bodyFrameLayout.AddChidren(btnCode);
            btnCode.ButtonClickEvent += (sender, e) =>
            {
                //发送验证码
                this.SetVerificationCode(btnCode);
            };
 
            //错误信息控件
            btnMsgControl = new NormalViewControl(800, 58, true);
            btnMsgControl.X = ControlCommonResourse.XXLeft;
            btnMsgControl.Y = rowCode.Bottom + Application.GetRealHeight(46);
            btnMsgControl.TextColor = 0xfff75858;
            btnMsgControl.TextID = R.MyInternationalizationString.uVerificationCodeErrorInputAgain;
            bodyFrameLayout.AddChidren(btnMsgControl);
            btnMsgControl.Visible = false;
 
            if (string.IsNullOrEmpty(UserCenterResourse.UserInfo.Phone) == true
                || string.IsNullOrEmpty(UserCenterResourse.UserInfo.Email) == true)
            {
                rowPhone.UseClickStatu = false;
                return;
            }
 
            //显示可以切换邮箱->一个可以遮住Body的东西
            var frameTran = new FrameLayoutStatuControl();
            frameTran.UseClickStatu = false;
            frameTran.BackgroundColor = UserCenterColor.Current.Transparent;
            bodyFrameLayout.AddChidren(frameTran);
            frameTran.Visible = false;
            frameTran.ButtonClickEvent += (sender, e) =>
            {
                frameTran.Visible = false;
            };
            var frameList = new FrameLayout();
            frameList.X = ControlCommonResourse.XXLeft - Application.GetRealWidth(17);
            frameList.Y = rowPhone.Bottom - ControlCommonResourse.BottomLineHeight - 1;
            frameList.Width = this.GetPictrueRealSize(628);
            frameList.Height = this.GetPictrueRealSize(176);
            frameTran.AddChidren(frameList);
            //动画用
            var frameAnimate = new FrameLayoutStatuControl();
            frameAnimate.UseClickStatu = false;
            frameList.AddChidren(frameAnimate);
 
            var btnPic = new PicViewControl(frameList.Width, frameList.Height, false);
            btnPic.UnSelectedImagePath = "Item/ForgotPswList.png";
            frameAnimate.AddChidren(btnPic);
            var btnEmail = new NormalViewControl(450, 58, true);
            btnEmail.X = this.GetPictrueRealSize(46);
            btnEmail.Y = this.GetPictrueRealSize(32);
            btnEmail.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnEmail.Text = UserCenterResourse.UserInfo.Email;
            frameAnimate.AddChidren(btnEmail);
            frameAnimate.ButtonClickEvent += (sender, e) =>
            {
                frameTran.Visible = false;
                string oldValue = txtPhone.Text;
                txtPhone.Text = btnEmail.Text;
                btnEmail.Text = oldValue;
 
                //当前选择的方式
                this.strPhoneEmail = txtPhone.Text;
            };
            rowPhone.ButtonClickEvent += (sender, e) =>
            {
                if (frameTran.Visible == false)
                {
                    frameTran.Visible = true;
                }
            };
        }
 
        #endregion
 
        #region ■ 发送验证码_________________________
 
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="btnCode"></param>
        private void SetVerificationCode(NormalViewControl btnCode)
        {
            string account = this.strPhoneEmail.StartsWith("+") == true ? UserCenterResourse.UserInfo.Phone : UserCenterResourse.UserInfo.Email;
            var sendCodePra = new SendCodePra();
            sendCodePra.Account = account;
            sendCodePra.AreaCode = Convert.ToInt32(UserCenterResourse.UserInfo.AreaCode);
            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ForgetPassword", false, sendCodePra);
            if (flage == false)
            {
                return;
            }
 
            //可以开始校验验证码了
            this.canCheckCode = true;
            //控件不能再次按下
            btnCode.CanClick = false;
            btnCode.BackgroundColor = 0xfffebca9;
            //?s后重发
            string repeat = Language.StringByID(R.MyInternationalizationString.RepeatSend1);
            //有效时间60秒
            int waitime = 60;
            btnCode.Text = waitime + "s" + repeat;
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    waitime--;
                    System.Threading.Thread.Sleep(1000);
                    if (waitime == 0)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            if (btnCode != null)
                            {
                                //获取验证码
                                btnCode.TextID = R.MyInternationalizationString.uGetVerificationCode;
                                //按键可以按下
                                btnCode.CanClick = true;
                                btnCode.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
                            }
                        });
                        break;
                    }
                    Application.RunOnMainThread(() =>
                    {
                        if (btnCode != null)
                        {
                            btnCode.Text = waitime + "s" + repeat;
                        }
                    });
                }
            });
        }
 
        #endregion
 
        #region ■ 验证码事件_________________________
 
        /// <summary>
        /// 验证码事件
        /// </summary>
        /// <param name="control"></param>
        /// <param name="value"></param>
        private void txtCodeValueChangedEvent(View control, string value)
        {
            if (btnMsgControl.Visible == true)
            {
                btnMsgControl.Visible = false;
            }
 
            //验证码长度
            int CodeLength = 6;
            if (value.Length < CodeLength)
            {
                return;
            }
            if (value.Length == CodeLength)
            {
                //还不能检测验证码
                if (this.canCheckCode == false)
                {
                    btnMsgControl.Visible = true;
                    return;
                }
                var txtCode = (TextInputControl)control;
                //终止事件
                txtCode.TextChangeEventHandler -= this.txtCodeValueChangedEvent;
                //验证验证码
                this.CheckVerificationCode(txtCode, value);
            }
        }
 
        #endregion
 
        #region ■ 校验验证码_________________________
 
        /// <summary>
        /// 验证验证码
        /// </summary>
        /// <returns></returns>
        private void CheckVerificationCode(TextInputControl txtCode, string code)
        {
            string account = this.strPhoneEmail.StartsWith("+") == true ? UserCenterResourse.UserInfo.Phone : UserCenterResourse.UserInfo.Email;
            var checkCodePra = new CheckCodePra();
            checkCodePra.Code = code;
            checkCodePra.Account = account;
 
            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ValidatorCode", false, checkCodePra);
            if (flage == false)
            {
                //验证码错误,请重新输入
                this.btnMsgControl.Visible = true;
                //事件还原
                txtCode.TextChangeEventHandler += this.txtCodeValueChangedEvent;
                return;
            }
 
            //自身关闭
            this.CloseForm();
            //指定新建密码模式
            this.LoadFormMethodByName("EditorSecondaryPasswordForm", "SetNewPasswordFormMode");
            this.LoadFormMethodByName("EditorGesturePasswordForm", "SetNewPasswordFormMode");
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 发送验证码的启动参数
        /// </summary>
        private class SendCodePra
        {
            /// <summary>
            /// 用户账号
            /// </summary>
            public string Account = UserCenterResourse.UserInfo.Phone;
            /// <summary>
            /// 公司编号,国内使用手机短信验证码时,此字段填入0,国外手机短信验证码,此字段填入4 
            /// </summary>
            public int Company = Common.CommonPage.PhoneZoneStr == "86" ? 0 : 4;
            /// <summary>
            /// 语言
            /// </summary>
            public string Language = Shared.Language.CurrentLanguage;
            /// <summary>
            /// 国家地区代码,手机号发送验证码时使用
            /// </summary>
            public int AreaCode = 0;
        }
 
        /// <summary>
        /// 发送验证码的启动参数
        /// </summary>
        private class CheckCodePra
        {
            /// <summary>
            /// 用户账号
            /// </summary>
            public string Account = UserCenterResourse.UserInfo.Phone;
            /// <summary>
            /// 验证码
            /// </summary>
            public string Code = "0";
            /// <summary>
            /// 语言
            /// </summary>
            public string Language = Shared.Language.CurrentLanguage;
            /// <summary>
            /// 国家地区代码,手机号发送验证码时使用
            /// </summary>
            public int AreaCode = Convert.ToInt32(UserCenterResourse.UserInfo.AreaCode);
        }
 
        #endregion
    }
}