wxr
2021-07-01 93c3423f0fdb79500b3779e2fcbd3a041be061fd
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
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 共通检测逻辑
    /// </summary>
    public class HdlCheckLogic
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 共通检测逻辑
        /// </summary>
        private static HdlCheckLogic m_Current = null;
        /// <summary>
        /// 共通检测逻辑
        /// </summary>
        public static HdlCheckLogic Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new HdlCheckLogic();
                }
                return m_Current;
            }
        }
 
        /// <summary>
        /// 验证认证的次数
        /// </summary>
        private int checkSecurityCount = 3;
 
        #endregion
 
        #region ■ 验证解锁认证_______________________
 
        /// <summary>
        /// 验证解锁认证
        /// </summary>
        /// <param name="addTopFrame">验证界面是否添加头部Frame(只对手势密码和数字密码有效)</param>
        /// <param name="successEvent">验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功)</param>
        /// <param name="loadPageBeforEvent">加载指定解锁认证界面之前的事件,0:取消当前验证并切换到其他方式,1:数字密码,2:手势密码,3:指纹密码,4:面容ID</param>
        public void CheckUnlockSecurity(bool addTopFrame, Action<int> successEvent, Action<string> loadPageBeforEvent = null)
        {
            //验证指纹和面容id都使用指纹验证
            if (UserInfo.Current.appUnlockType.Contains("3") || UserInfo.Current.appUnlockType.Contains("4"))
            {
                //先把这个东西置空
                TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
 
                TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType();
                if (type == TouchIDUtils.TouchIDSupperType.TouchID)
                {
                    //通知使用指纹验证
                    loadPageBeforEvent?.Invoke("3");
 
                    //Touch ID验证
                    TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent += (sender2, e2) =>
                    {
                        if (e2 == TouchIDUtils.TouchIDState.Success)
                        {
                            //次数还原
                            this.checkSecurityCount = 3;
 
                            //TouchID验证成功
                            successEvent?.Invoke(1);
                            successEvent = null;
                            loadPageBeforEvent = null;
                            TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null;
                        }
                        else if (e2 == TouchIDUtils.TouchIDState.InputPassword)
                        {
                            //通知取消了验证,切换为其他验证
                            loadPageBeforEvent?.Invoke("0");
 
                            //使用密码或者手势密码解锁认证
                            this.CheckUnlockSecurityByPassword(addTopFrame, successEvent, loadPageBeforEvent);
                        }
                    };
                    //提示数字密码验证还是绘制手势验证
                    string strTitle = this.GetVerificationTitleString();
 
                    TouchIDUtils.Instance.showTouchIDWithDescribe(strTitle, Language.StringByID(StringId.PleaseVerifyTheFingerprint));
                }
                //他关闭了手机的指纹验证
                else
                {
                    //使用密码或者手势密码解锁认证
                    this.CheckUnlockSecurityByPassword(addTopFrame, successEvent, loadPageBeforEvent);
                }
            }
            else
            {
                //使用密码或者手势密码解锁认证
                this.CheckUnlockSecurityByPassword(addTopFrame, successEvent, loadPageBeforEvent);
            }
        }
 
        /// <summary>
        /// 使用密码或者手势密码解锁认证
        /// </summary>
        /// <param name="addTopFrame">验证界面是否添加头部Frame(只对手势密码和数字密码有效)</param>
        /// <param name="successEvent">验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功)</param>
        /// <param name="loadPageBeforEvent">加载指定解锁认证界面之前的事件,1:数字密码,2:手势密码,3:指纹密码,4:面容ID</param>
        private void CheckUnlockSecurityByPassword(bool addTopFrame, Action<int> successEvent, Action<string> loadPageBeforEvent = null)
        {
            if (UserInfo.Current.appUnlockType.Contains("1"))
            {
                //通知使用数字密码验证
                loadPageBeforEvent?.Invoke("1");
 
                //显示数字密码解锁认证界面
                this.ShowAppNumPasswordSecurityForm(addTopFrame, successEvent);
            }
            else if (UserInfo.Current.appUnlockType.Contains("2"))
            {
                //通知使用手势密码验证
                loadPageBeforEvent?.Invoke("2");
 
                //显示手势密码解锁认证界面
                this.ShowAppGestureSecurityForm(addTopFrame, successEvent);
            }
            else
            {
                //没有设置有验证
                successEvent?.Invoke(0);
                successEvent = null;
            }
        }
 
        /// <summary>
        /// 显示数字密码解锁认证界面
        /// </summary>
        /// <param name="addTopFrame">验证界面是否添加头部Frame(只对手势密码和数字密码有效)</param>
        /// <param name="successEvent">验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功)</param>
        private void ShowAppNumPasswordSecurityForm(bool addTopFrame, Action<int> successEvent)
        {
            var form = new AppNumPasswordSecurityForm();
            form.AddForm(addTopFrame, Language.StringByID(StringId.PlsEntryPassword), string.Empty);
            form.ActionEvent += (div, password) =>
            {
                //密码输入结束
                if (div == 1)
                {
                    //密码正确
                    if (UserInfo.Current.appUnlockPasswrod == password)
                    {
                        //次数还原
                        this.checkSecurityCount = 3;
 
                        form.CloseForm();
                        //回调
                        successEvent?.Invoke(1);
                        successEvent = null;
                    }
                    else
                    {
                        this.checkSecurityCount--;
                        if (this.checkSecurityCount == 0)
                        {
                            //管理员身份验证失败,请重新登录
                            HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(StringId.CheckAdminFailAndLoginAgain));
                            HDLCommon.Current.Logout();
 
                            this.checkSecurityCount = 3;
                            return;
                        }
                        //验证失败,密码错误.
                        form.ShowErrorMsg(Language.StringByID(StringId.AuthenticationFailedPasswordError));
                    }
                }
            };
        }
 
        /// <summary>
        /// 显示手势密码解锁认证界面
        /// </summary>
        /// <param name="addTopFrame">验证界面是否添加头部Frame(只对手势密码和数字密码有效)</param>
        /// <param name="successEvent">验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功)</param>
        private void ShowAppGestureSecurityForm(bool addTopFrame, Action<int> successEvent)
        {
            var form = new AppGestureSecurityForm();
            form.AddForm(addTopFrame, Language.StringByID(StringId.VerifyGesturePassword), string.Empty);
            form.SetTitleText(string.Empty);
            form.ActionEvent += (div, password) =>
            {
                //密码输入结束
                if (div == 1)
                {
                    //密码正确
                    if (UserInfo.Current.appUnlockPasswrod == password)
                    {
                        //次数还原
                        this.checkSecurityCount = 3;
 
                        form.CloseForm();
                        //回调
                        successEvent?.Invoke(1);
                        successEvent = null;
                    }
                    else
                    {
                        this.checkSecurityCount--;
                        if (this.checkSecurityCount == 0)
                        {
                            //管理员身份验证失败,请重新登录
                            HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(StringId.CheckAdminFailAndLoginAgain));
                            HDLCommon.Current.Logout();
 
                            this.checkSecurityCount = 3;
                            return;
                        }
 
                        //验证失败,密码错误.
                        form.ShowErrorMsg(Language.StringByID(StringId.AuthenticationFailedPasswordError));
                    }
                }
            };
        }
 
        /// <summary>
        /// 判断是否数字验证、否则绘制手势验证
        /// </summary>
        /// <returns></returns>
        private string GetVerificationTitleString()
        {
            //优先使用密码验证,密码验证和手势验证不共存
            if (UserInfo.Current.appUnlockType.Contains("1") == true)
            {
                return Language.StringByID(StringId.PasswordVerification);
            }
            else
            {
                return Language.StringByID(StringId.GestureVerification);
            }
        }
 
        #endregion
    }
}