黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
 
namespace Shared.Phone.UserCenter.Password
{
    /// <summary>
    /// 验证原邮箱的画面
    /// </summary>
    public class CheckOldEmailForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 错误信息控件
        /// </summary>
        private NormalViewControl btnErrorMsg = null;
        /// <summary>
        /// 标记是否能够校验验证码了
        /// </summary>
        private bool canCheckCode = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设定标题
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorEmail));
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //已绑定邮箱
            var btnMsg1 = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(63), false);
            btnMsg1.Y = Application.GetRealHeight(167);
            btnMsg1.TextAlignment = TextAlignment.Center;
            btnMsg1.TextSize = 16;
            btnMsg1.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnMsg1.TextID = R.MyInternationalizationString.uHadBindEmail;
            bodyFrameLayout.AddChidren(btnMsg1);
 
            //邮箱
            var btnEmail = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(55), false);
            btnEmail.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnEmail.TextAlignment = TextAlignment.Center;
            btnEmail.TextSize = 16;
            btnEmail.Text = HdlUserCenterResourse.UserInfo.UserEmail;
            btnEmail.Y = btnMsg1.Bottom + Application.GetRealHeight(12);
            bodyFrameLayout.AddChidren(btnEmail);
 
            //修改邮箱前,请输入验证码确认您的身份
            var btnMsg2 = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(49), false);
            btnMsg2.Y = btnEmail.Bottom + Application.GetRealHeight(37);
            btnMsg2.TextAlignment = TextAlignment.Center;
            btnMsg2.TextSize = 12;
            btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnMsg2.TextID = R.MyInternationalizationString.uCheckAuthenticationBeforeEditorEmail;
            bodyFrameLayout.AddChidren(btnMsg2);
 
            //初始化验证码控件
            var btnCodeControl = new VerificationCodeControl(6);
            btnCodeControl.Y = Application.GetRealHeight(475);
            bodyFrameLayout.AddChidren(btnCodeControl);
            btnCodeControl.InitControl();
            btnCodeControl.TxtCodeChangeEvent += (sender, e) =>
            {
                if (btnErrorMsg.Visible == true)
                {
                    btnErrorMsg.Visible = false;
                }
            };
            btnCodeControl.FinishInputEvent += (value) =>
            {
                //校验验证码
                if (this.CheckVerificationCode(value) == false)
                {
                    //清空验证码
                    btnCodeControl.ClearInputValue();
                }
            };
 
            //验证码错误,请重新输入
            this.btnErrorMsg = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(58), false);
            btnErrorMsg.Y = Application.GetRealHeight(677);
            btnErrorMsg.TextAlignment = TextAlignment.Center;
            btnErrorMsg.TextColor = 0xfff75858;
            btnErrorMsg.TextID = R.MyInternationalizationString.uVerificationCodeErrorInputAgain;
            btnErrorMsg.IsBold = true;
            bodyFrameLayout.AddChidren(btnErrorMsg);
            btnErrorMsg.Visible = false;
 
            //获取验证码
            var btnNext = new BottomClickButton(688);
            btnNext.Y = Application.GetRealHeight(792);
            btnNext.TextID = R.MyInternationalizationString.uGetVerificationCode;
            bodyFrameLayout.AddChidren(btnNext);
            btnNext.ButtonClickEvent += (sender, e) =>
            {
                //清空输入的值
                btnCodeControl.ClearInputValue();
                //发送验证码到邮箱
                this.SendCodeToEmail(btnNext);
            };
        }
 
        #endregion
 
        #region ■ 发送验证码到邮箱___________________
 
        /// <summary>
        /// 发送验证码到邮箱
        /// </summary>
        private void SendCodeToEmail(BottomClickButton btnNext)
        {
            var errorMsg = HdlAccountLogic.Current.SendVeriCodeToEmail(HdlUserCenterResourse.UserInfo.UserEmail, VerCodeType.A其他);
            if (errorMsg != null)
            {
                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, errorMsg);
                return;
            }
 
            //可以开始校验验证码了
            this.canCheckCode = true;
            //控件不能再次按下
            btnNext.CanClick = false;
            //?s后重发
            string repeat = Language.StringByID(R.MyInternationalizationString.RepeatSend1);
            //有效时间60秒
            int waitime = 60;
            btnNext.Text = waitime + "s" + repeat;
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.Parent != null)
                {
                    waitime--;
                    System.Threading.Thread.Sleep(1000);
                    if (waitime == 0)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            if (btnNext != null)
                            {
                                //获取验证码
                                btnNext.TextID = R.MyInternationalizationString.uGetVerificationCode;
                                //按键可以按下
                                btnNext.CanClick = true;
                            }
                        });
                        break;
                    }
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        if (btnNext != null)
                        {
                            btnNext.Text = waitime + "s" + repeat;
                        }
                    }, ShowErrorMode.NO);
                }
            });
        }
 
        #endregion
 
        #region ■ 校验验证码_________________________
 
        /// <summary>
        /// 验证验证码
        /// </summary>
        /// <returns></returns>
        private bool CheckVerificationCode(string code)
        {
            if (this.canCheckCode == false)
            {
                //验证码错误,请重新输入
                this.btnErrorMsg.Visible = true;
                return false;
            }
 
            var result = HdlAccountLogic.Current.CheckVeriCode(HdlUserCenterResourse.UserInfo.UserEmail, VerCodeType.A其他, code);
            if (result == false)
            {
                //验证码错误,请重新输入
                this.btnErrorMsg.Visible = true;
                return false;
            }
 
            var from = new CheckNewEmailForm();
            base.AddFormAndCloseNowForm(from);
 
            return true;
        }
 
        #endregion
    }
}