using Shared; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.Stan { /// /// 共通检测逻辑 /// public class HdlCheckLogic { #region ■ 变量声明___________________________ /// /// 共通检测逻辑 /// private static HdlCheckLogic m_Current = null; /// /// 共通检测逻辑 /// public static HdlCheckLogic Current { get { if (m_Current == null) { m_Current = new HdlCheckLogic(); } return m_Current; } } /// /// 验证认证的次数 /// private int checkSecurityCount = 3; #endregion #region ■ 验证解锁认证_______________________ /// /// 验证解锁认证 /// /// 验证界面是否添加头部Frame(只对手势密码和数字密码有效) /// 验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功) /// 加载指定解锁认证界面之前的事件,0:取消当前验证并切换到其他方式,1:数字密码,2:手势密码,3:指纹密码,4:面容ID public void CheckUnlockSecurity(bool addTopFrame, Action successEvent, Action 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); } } /// /// 使用密码或者手势密码解锁认证 /// /// 验证界面是否添加头部Frame(只对手势密码和数字密码有效) /// 验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功) /// 加载指定解锁认证界面之前的事件,1:数字密码,2:手势密码,3:指纹密码,4:面容ID private void CheckUnlockSecurityByPassword(bool addTopFrame, Action successEvent, Action 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; } } /// /// 显示数字密码解锁认证界面 /// /// 验证界面是否添加头部Frame(只对手势密码和数字密码有效) /// 验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功) private void ShowAppNumPasswordSecurityForm(bool addTopFrame, Action 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)); } } }; } /// /// 显示手势密码解锁认证界面 /// /// 验证界面是否添加头部Frame(只对手势密码和数字密码有效) /// 验证成功之后的回调函数,失败不会回调(0:没有设置有验证 1:验证成功) private void ShowAppGestureSecurityForm(bool addTopFrame, Action 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)); } } }; } /// /// 判断是否数字验证、否则绘制手势验证 /// /// private string GetVerificationTitleString() { //优先使用密码验证,密码验证和手势验证不共存 if (UserInfo.Current.appUnlockType.Contains("1") == true) { return Language.StringByID(StringId.PasswordVerification); } else { return Language.StringByID(StringId.GestureVerification); } } #endregion } }