黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter.Password
{
    /// <summary>
    /// 重置账号密码的界面
    /// </summary>
    public class ResetAccountPasswordForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uResetPassword));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameRow1 = new FrameLayout();
            frameRow1.Height = Application.GetRealHeight(23) + ControlCommonResourse.ListViewRowHeight;
            frameRow1.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameRow1);
 
            //请输入新密码
            var rowNewPsw = new FrameRowControl(Application.GetRealHeight(5) / 2);
            //关闭状态提示
            rowNewPsw.UseClickStatu = false;
            rowNewPsw.Y = Application.GetRealHeight(23);
            frameRow1.AddChidren(rowNewPsw);
            var txtNewPsw = rowNewPsw.AddLeftInput("", 800);
            txtNewPsw.SecureTextEntry = true;
            txtNewPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputNewPassword);
            //底线
            rowNewPsw.AddBottomLine();
            //图标
            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;
            };
            //Row1的错误信息
            var btnErrorRow1 = new NormalViewControl(800, 58, true);
            btnErrorRow1.X = ControlCommonResourse.XXLeft;
            btnErrorRow1.Y = rowNewPsw.Bottom + Application.GetRealHeight(29);
            btnErrorRow1.TextColor = 0xfff75858;
            frameRow1.AddChidren(btnErrorRow1);
 
            var frameRow2 = new FrameLayout();
            frameRow2.Y = frameRow1.Bottom;
            frameRow2.Height = Application.GetRealHeight(150) + ControlCommonResourse.ListViewRowHeight;
            bodyFrameLayout.AddChidren(frameRow2);
            var frameTemp = new FrameLayout();
            frameTemp.Height = Application.GetRealHeight(161);
            frameTemp.BackgroundColor = UserCenterColor.Current.White;
            frameRow2.AddChidren(frameTemp);
            //请重复输入新密码
            var rowConfirmPsw = new FrameRowControl(Application.GetRealHeight(5) / 2);
            //关闭状态提示
            rowConfirmPsw.UseClickStatu = false;
            rowConfirmPsw.Y = Application.GetRealHeight(10);
            frameTemp.AddChidren(rowConfirmPsw);
            var txtConfirmPsw = rowConfirmPsw.AddLeftInput("", 800);
            txtConfirmPsw.SecureTextEntry = true;
            txtConfirmPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseRepeatInputNewPassword);
            //图标
            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;
            };
            //Row2的错误信息
            var btnErrorRow2 = new NormalViewControl(800, 58, true);
            btnErrorRow2.X = ControlCommonResourse.XXLeft;
            btnErrorRow2.Y = frameTemp.Bottom + Application.GetRealHeight(29);
            btnErrorRow2.TextColor = 0xfff75858;
            frameRow2.AddChidren(btnErrorRow2);
 
            //重置密码
            var btnReset = new BottomClickButton(688);
            btnReset.TextID = R.MyInternationalizationString.uResetPassword;
            btnReset.Y = Application.GetRealHeight(706);
            bodyFrameLayout.AddChidren(btnReset);
            btnReset.ButtonClickEvent += (sender, e) =>
            {
                //密码检测
                var flage = this.CheckPassword(frameRow1, frameRow2, btnErrorRow1, btnErrorRow2, txtNewPsw.Text, txtConfirmPsw.Text);
                if (flage == false)
                {
                    return;
                }
                //重置密码
                this.ResetPassword(txtNewPsw.Text, txtConfirmPsw.Text);
            };
        }
 
        #endregion
 
        #region ■ 重置密码___________________________
 
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="newPsw">新密码</param>
        /// <param name="newPsw2">二次确认密码</param>
        private void ResetPassword(string newPsw, string newPsw2)
        {
            var pra = new ResetPswPra();
            pra.Password = newPsw;
            pra.AgainPassword = newPsw2;
            //更改密码
            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ResetPassword", false, pra);
            if (flage == false)
            {
                return;
            }
            //密码已经修改,请重新登录
            string msg = Language.StringByID(R.MyInternationalizationString.uPasswordIsHadChangedAndLoginAgain);
            this.ShowMassage(ShowMsgType.Normal, msg, () =>
            {
                //从新登录
                UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
            }, Language.StringByID(R.MyInternationalizationString.Login));
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 密码检测
        /// </summary>
        /// <param name="frameRow1"></param>
        /// <param name="frameRow2"></param>
        /// <param name="btnError1"></param>
        /// <param name="btnError2"></param>
        /// <param name="newPsw">输入的新密码</param>
        /// <param name="newPsw2">输入的确认密码</param>
        /// <returns></returns>
        private bool CheckPassword(FrameLayout frameRow1,FrameLayout frameRow2,
            NormalViewControl btnError1, NormalViewControl btnError2,
            string newPsw, string newPsw2)
        {
            //还原
            frameRow1.Height = Application.GetRealHeight(23) + ControlCommonResourse.ListViewRowHeight;
            frameRow2.Y = frameRow1.Bottom;
            btnError2.Text = string.Empty;
 
            if (newPsw == string.Empty)
            {
                //请输入新密码
                btnError1.TextID = R.MyInternationalizationString.uPleaseInputNewPassword;
                frameRow1.Height += Application.GetRealHeight(133);
                frameRow2.Y = frameRow1.Bottom;
                return false;
            }
            if (newPsw2 == string.Empty)
            {
                //请重复输入新密码
                btnError2.TextID = R.MyInternationalizationString.uPleaseRepeatInputNewPassword;
                return false;
            }
            if (newPsw != newPsw2)
            {
                //确认密码不一致,请重新输入
                btnError2.TextID = R.MyInternationalizationString.SecondPswNotEqual1;
                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");
                }
                btnError1.Text = textValue;
                frameRow1.Height += Application.GetRealHeight(133);
                frameRow2.Y = frameRow1.Bottom;
                return false;
            }
 
            return true;
        }
 
        #endregion
 
        #region ■ 结构体_____________________________
 
        /// <summary>
        /// 重置密码的启动参数
        /// </summary>
        private class ResetPswPra
        {
            /// <summary>
            /// 用户账号
            /// </summary>
            public string Account = UserCenterResourse.UserInfo.Account;
            /// <summary>
            /// 国家地区代码,手机号发送验证码时使用
            /// </summary>
            public int AreaCode = Convert.ToInt32(UserCenterResourse.UserInfo.AreaCode);
            /// <summary>
            /// 新密码
            /// </summary>
            public string Password = string.Empty;
            /// <summary>
            /// 二次确认密码
            /// </summary>
            public string AgainPassword = string.Empty;
        }
        #endregion
    }
}