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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
using System;
using Shared.Common;
using System.Timers;
using System.Text.RegularExpressions;
 
namespace Shared.Phone.UserCenter.User
{
    /// <summary>
    /// 根据邮箱找回密码
    /// </summary>
    public class ForgotPasswordByEmailForm : UserCenterCommonForm
    {
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设定标题
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ForgotPassword));
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            this.ShowForgotPWD();
        }
 
        #endregion
 
        #region ■ 以下为复制郭雪城的代码_____________
 
        /// <summary>
        /// 
        /// </summary>
        void ShowForgotPWD()
        {
            var t = new Timer();
            var dateBegin = new DateTime();
 
            #region --midFL--
 
            var accountTIPS = new Button()
            {
                Width = Application.GetRealWidth(1080 - CommonPage.XLeft * 2),
                Height = Application.GetRealHeight(100),
                TextAlignment = TextAlignment.CenterLeft,
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
                TextID = R.MyInternationalizationString.PleaseInputTheEmailAndYouWillHaveVerificatoinCode
            };
            bodyFrameLayout.AddChidren(accountTIPS);
 
            var accountFL = new FrameLayout()
            {
                Y = accountTIPS.Bottom + Application.GetRealHeight(100),
                Height = Application.GetRealHeight(100)
            };
            bodyFrameLayout.AddChidren(accountFL);
 
            var accountET = new EditText()
            {
                X = Application.GetRealWidth(CommonPage.XLeft),
                Width = Application.GetRealWidth(800),
                Height = Application.GetRealHeight(100) - 1,
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputEmail),
                PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor
            };
            accountFL.AddChidren(accountET);
 
            var accountLine = new FrameLayout()
            {
                Y = Application.GetRealHeight(100) - 1,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCLineColor
            };
            accountFL.AddChidren(accountLine);
 
            var verificationCodeFL = new FrameLayout()
            {
                Y = accountFL.Bottom + Application.GetRealHeight(100),
                Height = Application.GetRealHeight(100)
            };
            bodyFrameLayout.AddChidren(verificationCodeFL);
 
            var verificationCodeET = new EditText()
            {
                X = Application.GetRealWidth(CommonPage.XLeft),
                Width = Application.GetRealWidth(500),
                Height = Application.GetRealHeight(100) - 1,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputVerificationCode),
                PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor
            };
            verificationCodeFL.AddChidren(verificationCodeET);
 
            var verificationCodeLine = new FrameLayout()
            {
                Y = Application.GetRealHeight(100) - 1,
                Height = 1,
                BackgroundColor = ZigbeeColor.Current.GXCLineColor
            };
            verificationCodeFL.AddChidren(verificationCodeLine);
 
            var sendCodeBtn = new Button()
            {
                X = Application.GetRealWidth(1080 - 400 - CommonPage.XLeft),
                Width = Application.GetRealWidth(400),
                Y = Application.GetRealHeight(100) + verificationCodeFL.Bottom,
                Height = Application.GetRealHeight(100),
                TextID = R.MyInternationalizationString.SendVerificationCode,
                TextColor = ZigbeeColor.Current.GXCButtonUnselectedColor,
                SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor,
                TextAlignment = TextAlignment.CenterRight,
                Enable = false,
                IsSelected = false,
            };
            bodyFrameLayout.AddChidren(sendCodeBtn);
 
            var resetPWDBtn = new Button()
            {
                Width = Application.GetRealWidth(700),
                Y = Application.GetRealHeight(1920 - 220 - 400),
                Height = Application.GetRealHeight(110),
                Radius = (uint)Application.GetRealHeight(55),
                TextID = R.MyInternationalizationString.ResetPWD,
                TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                TextAlignment = TextAlignment.Center,
                TextSize = 15,
                BackgroundColor = ZigbeeColor.Current.GXCButtonUnselectedColor,
                SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor,
                Gravity = Gravity.CenterHorizontal,
                Enable = false,
                IsSelected = false
            };
            bodyFrameLayout.AddChidren(resetPWDBtn);
            //错误提示Btn
            var loginErrorBtn = new Button()
            {
                Y = resetPWDBtn.Bottom + Application.GetRealHeight(50),
                Width = Application.GetRealWidth(1080 - 100),
                Height = Application.GetRealHeight(110),
                TextColor = ZigbeeColor.Current.GXCRedColor,
                Gravity = Gravity.CenterHorizontal
            };
            bodyFrameLayout.AddChidren(loginErrorBtn);
            #endregion
 
            #region --event--
            accountET.TextChangeEventHandler += (sender, e) =>
            {
                loginErrorBtn.Text = "";
                if (accountET.Text.Trim().Length > 0)
                {
                    sendCodeBtn.Enable = sendCodeBtn.IsSelected = true;
                }
                else
                {
                    sendCodeBtn.Enable = sendCodeBtn.IsSelected = false;
                }
            };
            verificationCodeET.TextChangeEventHandler += (sender, e) =>
            {
                loginErrorBtn.Text = "";
                if (verificationCodeET.Text.Trim().Length > 0)
                {
                    resetPWDBtn.Enable = resetPWDBtn.IsSelected = true;
                }
                else
                {
                    resetPWDBtn.Enable = resetPWDBtn.IsSelected = false;
                }
            };
 
            sendCodeBtn.MouseUpEventHandler += async (sender, e) =>
            {
                var reg = new Regex(CommonPage.EmailRegexStr);
                var ss = reg.Match(accountET.Text.Trim());
                //校验邮箱
                if (!ss.Success)
                {
                    var aler = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.PleaseInputTheCorrectEmail), Language.StringByID(R.MyInternationalizationString.Confrim));
                    aler.Show();
                    accountET.Text = "";
                }
                else
                {
                    string phoneNum = accountET.Text.Trim();
                    CommonPage.Loading.Start();
                    try
                    {
                        var reqDtoSignPhone = new SendDataToServer.LoginSendVerCodeObj()
                        {
                            Account = phoneNum,
                            Company = 0,
                            AreaCode = 0,
                            Language = CommonPage.ZigBeeLanguage
                        };
                        var requesetJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDtoSignPhone);
                        var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/LoginSendVerCode", System.Text.Encoding.UTF8.GetBytes(requesetJson));
                        if (requestRevertObj == null)
                        {
                            CommonPage.Instance.FailureToServer();
                            return;
                        }
                        var stateCodeStr = requestRevertObj.StateCode.ToUpper();
                        if (stateCodeStr == "SUCCESS")
                        {
                            TimeBegin();
                            var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SendVerificationCodeSuccess), Language.StringByID(R.MyInternationalizationString.Confrim));
                            alert.Show();
                        }
                        else if (stateCodeStr == "PARAMETEROREMPTY")
                        {
                            //提供的参数错误
                            loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY;
                            CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY);
                        }
                        else if (stateCodeStr == "ACCOUNTNOEXISTS")
                        {
                            //账号不存在
                            loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS;
                            CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ACCOUNTNOEXISTS);
                        }
                        else
                        {
                            loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
                            CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed);
                        }
                    }
                    catch
                    {
                        loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
                    }
                    finally
                    {
                        CommonPage.Loading.Hide();
                    }
                }
            };
 
            resetPWDBtn.MouseUpEventHandler += async (sender, e) =>
            {
                var vCode = verificationCodeET.Text.Trim();
                var vPhone = accountET.Text.Trim();
                CommonPage.Loading.Start();
                try
                {
                    var reqDto = new SendDataToServer.ValidatorCodeObj()
                    {
                        Account = vPhone,
                        Code = int.Parse(vCode),
                        AreaCode = 0,
                        Language = CommonPage.ZigBeeLanguage
                    };
                    var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto);
                    //验证验证码
                    var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/ValidatorCode", System.Text.Encoding.UTF8.GetBytes(requestJson));
                    if (requestRevertObj == null)
                    {
                        CommonPage.Instance.FailureToServer();
                        return;
                    }
                    var stateCodeStr = requestRevertObj.StateCode.ToUpper();
                    if (stateCodeStr == "SUCCESS")
                    {
                        ModifyPWD(vPhone);
                    }
                    else if (stateCodeStr == "VALIDCODEANDPHONENOEQUAL")
                    {
                        //验证码错误
                        loginErrorBtn.TextID = R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL;
                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL);
                    }
                    else if (stateCodeStr == "SENDFAIL")
                    {
                        //验证码发送失败
                        loginErrorBtn.TextID = R.MyInternationalizationString.SENDFAIL;
                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.SENDFAIL);
                    }
                    else if (stateCodeStr == "ACCOUNTNOEXISTS")
                    {
                        //账号不存在
                        loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS;
                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ACCOUNTNOEXISTS);
                    }
                    else if (stateCodeStr == "PARAMETEROREMPTY")
                    {
                        //提供的参数错误
                        loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY;
                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY);
                    }
                    else
                    {
                        loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
                        CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed);
                    }
                }
                catch
                {
                    loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed;
                }
                finally
                {
                    CommonPage.Loading.Hide();
                }
            };
            void ModifyPWD(string account)
            {
                var newPWD = new ForgotPasswordSetNewPasswordForm();
                this.AddForm(newPWD, account, "email", string.Empty);
            }
            void TimeBegin()
            {
                t.Interval = 1000;
                t.AutoReset = true;
                t.Enabled = true;
                t.Elapsed += new ElapsedEventHandler(TimeOut);
                //启动计时器倒计时-60s
                t.Start();
                dateBegin = DateTime.Now;
            }
            void TimeOut(object source, System.Timers.ElapsedEventArgs e)
            {
                var span = DateTime.Now - dateBegin;
                if (span.TotalSeconds <= 61)
                {
                    Application.RunOnMainThread(() =>
                    {
                        sendCodeBtn.Text = Convert.ToInt16((60 - span.TotalSeconds)) + "s" + Language.StringByID(R.MyInternationalizationString.SendVerificationCode);
                        sendCodeBtn.Enable = false;
                    });
                }
                else
                {
                    Application.RunOnMainThread(() =>
                    {
                        sendCodeBtn.Enable = true;
                        sendCodeBtn.TextID = R.MyInternationalizationString.SendVerificationCode;
                        t.Stop();
                        t.Close();
                    });
                }
            }
            #endregion
        }
 
        #endregion
    }
}