黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// 二次密码验证界面
    /// </summary>
    public class PswSecondarySecurityForm : DialogCommonForm
    {
        #region ■ 变量声明___________________________
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_TouchText">Touch ID验证的显示文本</param>
        /// <param name="i_PasswordText">密码验证的显示文本</param>
        /// <param name="i_GestureText">手势验证的显示文本</param>
        /// <param name="SuccessAction">验证成功后的回调函数,如果不成功,不会调用这个东西</param>
        public void ShowForm(string i_TouchText, string i_PasswordText, string i_GestureText, Action SuccessAction)
        {
            //初始化中部信息
            this.InitMiddleFrame(i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        /// <param name="i_TouchText">Touch ID验证的显示文本</param>
        /// <param name="i_PasswordText">密码验证的显示文本</param>
        /// <param name="i_GestureText">手势验证的显示文本</param>
        /// <param name="SuccessAction">验证成功后的回调函数,如果不成功,不会调用这个东西</param>
        private void InitMiddleFrame(string i_TouchText, string i_PasswordText, string i_GestureText, Action SuccessAction)
        {
            var frameBack = new FrameLayout();
            frameBack.Y = Application.GetRealHeight(101);
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.Width = Application.GetRealWidth(965);
            frameBack.Height = Application.GetRealHeight(1711);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Radius = (uint)Application.GetRealHeight(17);
            bodyFrameLayout.AddChidren(frameBack);
 
            //密码输入控件
            var pswControl = new PswNumberInputControl(i_PasswordText, 4);
            pswControl.Gravity = Gravity.CenterHorizontal;
            pswControl.Y = Application.GetRealHeight(81);
            frameBack.AddChidren(pswControl);
            pswControl.InitControl();
            //改变删除按钮的坐标
            pswControl.ChangedDeleteButtonPoint(-1, pswControl.Height, false);
            //添加关闭按钮
            var btnClose = pswControl.AddCloseButton();
            btnClose.ButtonClickEvent += (sender, e) =>
            {
                this.CloseForm();
            };
            pswControl.FinishInputEvent += (strPsw) =>
            {
                if (HdlUserCenterResourse.AccountOption.PswAuthentication != strPsw)
                {
                    HdlUserCenterResourse.AccountOption.PasswordInputCount--;
                    if (HdlUserCenterResourse.AccountOption.PasswordInputCount <= 0)
                    {
                        //管理员身份验证失败,请重新登录
                        string msg2 = Language.StringByID(R.MyInternationalizationString.uCheckAdministratorFailAndReload);
                        this.ShowMassage(ShowMsgType.Tip, msg2);
                        HdlAccountLogic.Current.ReLoginAgain(Common.Config.Instance.Account);
                        return;
                    }
                    //密码错误,请重新输入
                    pswControl.SetErrorMsg(Language.StringByID(R.MyInternationalizationString.uOldPsswordIsError));
                    return;
                }
                //重置剩余密码次数
                HdlUserCenterResourse.AccountOption.ResetPasswordCount();
                //界面关闭
                this.CloseForm();
                SuccessAction?.Invoke();
                SuccessAction = null;
            };
 
            //手势开锁
            var btnGesture = new BottomLeftClickButton(frameBack.Width / 2, Application.GetRealHeight(127));
            frameBack.AddChidren(btnGesture);
            btnGesture.InitControl(i_GestureText);
            if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == true)
            {
                //没有启用手势开锁
                btnGesture.CanClick = false;
            }
 
            btnGesture.ButtonClickEvent += (sender, e) =>
            {
                var form = new PswGestureSecirityForm();
                this.AddFormAndCloseNowForm(form, i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
            };
 
            //Touch ID开锁
            var btnTouch = new BottomRightClickButton(frameBack.Width - btnGesture.Width, btnGesture.Height);
            frameBack.AddChidren(btnTouch);
            btnTouch.InitControl(i_TouchText);
            if (HdlUserCenterResourse.AccountOption.FingerprintAuthentication == false)
            {
                //没有启用Touch ID
                btnTouch.CanClick = false;
            }
 
            btnTouch.ButtonClickEvent += (sender, e) =>
            {
                //二次检测
                TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType();
                if (type != TouchIDUtils.TouchIDSupperType.TouchID)
                {
                    return;
                }
 
                //界面关闭
                this.CloseForm();
 
                TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent += (sender2, e2) =>
                {
                    if (e2 == TouchIDUtils.TouchIDState.Success)
                    {
                        TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
 
                        //TouchID验证成功
                        SuccessAction?.Invoke();
                        SuccessAction = null;
                    }
                    else if (e2 == TouchIDUtils.TouchIDState.InputPassword)
                    {
                        TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
 
                        //密码验证
                        if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.PswAuthentication) == false)
                        {
                            var form = new PswSecondarySecurityForm();
                            this.AddFormAndCloseNowForm(form, i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
                        }
                        //手势验证
                        else if (string.IsNullOrEmpty(HdlUserCenterResourse.AccountOption.GestureAuthentication) == false)
                        {
                            var form = new PswGestureSecirityForm();
                            this.AddFormAndCloseNowForm(form, i_TouchText, i_PasswordText, i_GestureText, SuccessAction);
                        }
                        else
                        {
                            //没有设置密码验证
                            this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uPasswordAuthenticationNotSettion));
                        }
                    }
                };
                TouchIDUtils.Instance.showTouchIDWithDescribe(null, null);
            };
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        public override void CloseFormBefore()
        {
            //取消事件
            TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
 
            base.CloseFormBefore();
        }
 
        #endregion
    }
}