New file |
| | |
| | | using Shared.Common; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 各种正确检测_______________________ |
| | | |
| | | /// <summary> |
| | | /// 判断是否包含大写字母 |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if contain upper was checked, <c>false</c> otherwise.</returns> |
| | | /// <param name="value">Value.</param> |
| | | public bool CheckContainUpper(string value) |
| | | { |
| | | Regex reg = new Regex("[A-Z]+"); |
| | | return reg.IsMatch(value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否包含小写字母 |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns> |
| | | /// <param name="value">Value.</param> |
| | | public bool CheckContainLower(string value) |
| | | { |
| | | Regex reg = new Regex("[a-z]+"); |
| | | return reg.IsMatch(value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否包含数字 |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns> |
| | | /// <param name="value">Value.</param> |
| | | public bool CheckContainNum(string value) |
| | | { |
| | | Regex reg = new Regex("[0-9]+"); |
| | | return reg.IsMatch(value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否包含符号 |
| | | /// </summary> |
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns> |
| | | /// <param name="value">Value.</param> |
| | | public bool CheckContainSymbol(string value) |
| | | { |
| | | Regex reg = new Regex("([^a-z0-9A-Z])+"); |
| | | return reg.IsMatch(value); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测邮箱是否合法 |
| | | /// </summary> |
| | | /// <param name="email"></param> |
| | | /// <returns></returns> |
| | | public bool CheckEmail(string email) |
| | | { |
| | | Regex reg = new Regex(CommonPage.EmailRegexStr); |
| | | return reg.IsMatch(email); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测手机号是否合法 |
| | | /// </summary> |
| | | /// <param name="phoneNumber">手机号</param> |
| | | /// <param name="areaCode">地区代码</param> |
| | | /// <returns></returns> |
| | | public bool CheckPhoneNumber(string phoneNumber, string areaCode) |
| | | { |
| | | //校验外国手机号 |
| | | if (areaCode != "86") |
| | | { |
| | | Regex reg = new Regex(CommonPage.PhoneForForeignRegexStr); |
| | | return reg.IsMatch(phoneNumber); |
| | | } |
| | | |
| | | //校验国内手机号 |
| | | if (phoneNumber.Length > 11) |
| | | { |
| | | return false; |
| | | } |
| | | else if (phoneNumber.Length == 11) |
| | | { |
| | | Regex reg = new Regex(CommonPage.PhoneRegexStr); |
| | | return reg.IsMatch(phoneNumber); |
| | | } |
| | | else |
| | | { |
| | | //正则表达式判断是否数字 |
| | | Regex reg = new Regex("^[0-9]*$"); |
| | | return reg.IsMatch(phoneNumber); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测字符串是否是纯数字 |
| | | /// </summary> |
| | | /// <param name="i_text"></param> |
| | | /// <returns></returns> |
| | | public bool CheckIsNumber(string i_text) |
| | | { |
| | | foreach (var c in i_text) |
| | | { |
| | | if (char.IsNumber(c) == false) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 检测网关共通错误状态码_____________ |
| | | |
| | | /// <summary> |
| | | /// <para>检测网关返回的共通错误状态码(返回null则代表没有错误),支持状态码为</para> |
| | | /// <para>1:网关无法解析命令数据。</para> |
| | | /// <para>2:协调器正在升级或备份/恢复数据</para> |
| | | /// <para>3:操作设备/组/场景不存在</para> |
| | | /// <para>4:其他错误</para> |
| | | /// <para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para> |
| | | /// </summary> |
| | | /// <param name="resultData">网关返回的resultData,里面有【errorResponData】这个东西的那种对象</param> |
| | | /// <returns></returns> |
| | | public string CheckCommonErrorCode(object resultData) |
| | | { |
| | | if (resultData == null) |
| | | { |
| | | return null; |
| | | } |
| | | Type myType = resultData.GetType(); |
| | | object errorObj = myType.InvokeMember("errorResponData", System.Reflection.BindingFlags.GetField, null, resultData, null); |
| | | if (errorObj == null) |
| | | { |
| | | return null; |
| | | } |
| | | Type type = errorObj.GetType(); |
| | | var code = type.InvokeMember("Error", System.Reflection.BindingFlags.GetField, null, errorObj, null); |
| | | int errorCode = Convert.ToInt32(code); |
| | | |
| | | return CheckCommonErrorCode(errorCode); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// <para>检测网关返回的共通错误状态码(返回null则代表没有错误),支持状态码为</para> |
| | | /// <para>1:网关无法解析命令数据。</para> |
| | | /// <para>2:协调器正在升级或备份/恢复数据</para> |
| | | /// <para>3:操作设备/组/场景不存在</para> |
| | | /// <para>4:其他错误</para> |
| | | /// <para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para> |
| | | /// </summary> |
| | | /// <param name="errorCode">错误代码</param> |
| | | /// <returns></returns> |
| | | public string CheckCommonErrorCode(int errorCode) |
| | | { |
| | | if (errorCode == 1) |
| | | { |
| | | //网关无法解析命令数据 |
| | | return Language.StringByID(R.MyInternationalizationString.uGatewayCannotResolveCommand); |
| | | } |
| | | else if (errorCode == 2) |
| | | { |
| | | //协调器正在升级或备份或恢复数据中 |
| | | return Language.StringByID(R.MyInternationalizationString.uCoordinatorIsUpOrBackupOrRecovering); |
| | | } |
| | | else if (errorCode == 3) |
| | | { |
| | | //目标设备不存在 |
| | | return Language.StringByID(R.MyInternationalizationString.uTargetDeviceIsNotExsit); |
| | | } |
| | | else if (errorCode == 4) |
| | | { |
| | | //出现未知错误,请稍后再试 |
| | | return Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain); |
| | | } |
| | | else if (errorCode == 5) |
| | | { |
| | | //数据传输错误,请稍后再试 |
| | | return Language.StringByID(R.MyInternationalizationString.uDataTransmissionFailAndResetAgain); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 检测账号是否已经退出_______________ |
| | | |
| | | /// <summary> |
| | | /// 检测账号是否已经退出 true:已经退出 false:没有退出 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public bool IsAccountLoginOut() |
| | | { |
| | | return Config.Instance.HomeId == string.Empty; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 二次安全验证_______________________ |
| | | |
| | | /// <summary> |
| | | /// 执行二次安全验证(三种验证的标题使用默认值:Touch ID验证,密码验证,手势验证) |
| | | /// </summary> |
| | | /// <param name="SuccessAction">如果设置有验证方式,并且验证成功后才会调用的回调函数,不然不会调用这个东西</param> |
| | | /// <param name="NotSettionAction">如果完全没有设置有验证方式,才会调用的回调函数,不然不会调用这个东西(取消输入不会调用这个东西)</param> |
| | | public void CheckSecondarySecurity(Action SuccessAction, Action NotSettionAction = null) |
| | | { |
| | | CheckSecondarySecurity( |
| | | Language.StringByID(R.MyInternationalizationString.uTouchIDCheck), |
| | | Language.StringByID(R.MyInternationalizationString.uPasswordAuthentication), |
| | | Language.StringByID(R.MyInternationalizationString.uGestureAuthentication), |
| | | SuccessAction, NotSettionAction); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 执行二次安全验证 |
| | | /// </summary> |
| | | /// <param name="i_TouchText">Touch ID验证的显示文本</param> |
| | | /// <param name="i_PasswordText">密码验证的显示文本</param> |
| | | /// <param name="i_GestureText">手势验证的显示文本</param> |
| | | /// <param name="SuccessAction">如果设置有验证方式,并且验证成功后才会调用的回调函数,不然不会调用这个东西</param> |
| | | /// <param name="NotSettionAction">如果完全没有设置有验证方式,才会调用的回调函数,不然不会调用这个东西(取消输入不会调用这个东西)</param> |
| | | public void CheckSecondarySecurity(string i_TouchText, string i_PasswordText, string i_GestureText, Action SuccessAction, Action NotSettionAction = null) |
| | | { |
| | | //先把这个东西置空 |
| | | TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null; |
| | | |
| | | TouchIDUtils.TouchIDSupperType type = TouchIDUtils.getTouchIDSupperType(); |
| | | if (type == TouchIDUtils.TouchIDSupperType.TouchID && UserCenterResourse.AccountOption.FingerprintAuthentication == true) |
| | | { |
| | | //Touch ID验证 |
| | | TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent += (sender2, e2) => |
| | | { |
| | | if (e2 == TouchIDUtils.TouchIDState.Success) |
| | | { |
| | | //TouchID验证成功 |
| | | SuccessAction?.Invoke(); |
| | | SuccessAction = null; |
| | | TouchIDUtils.Instance.OnHDLTouchIDStateBackEvent = null; |
| | | } |
| | | else if (e2 == TouchIDUtils.TouchIDState.InputPassword) |
| | | { |
| | | //密码验证 |
| | | if (string.IsNullOrEmpty(UserCenterResourse.AccountOption.PswAuthentication) == false) |
| | | { |
| | | var form = new PswSecondarySecurityForm(); |
| | | form.AddForm(i_TouchText, i_PasswordText, i_GestureText, SuccessAction); |
| | | } |
| | | //手势验证 |
| | | else if (string.IsNullOrEmpty(UserCenterResourse.AccountOption.GestureAuthentication) == false) |
| | | { |
| | | var form = new PswGestureSecirityForm(); |
| | | form.AddForm(i_TouchText, i_PasswordText, i_GestureText, SuccessAction); |
| | | } |
| | | else |
| | | { |
| | | //没有设置密码验证 |
| | | var alert = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uPasswordAuthenticationNotSettion)); |
| | | alert.Show(); |
| | | } |
| | | } |
| | | }; |
| | | TouchIDUtils.Instance.showTouchIDWithDescribe(null, null); |
| | | NotSettionAction = null; |
| | | } |
| | | else if (string.IsNullOrEmpty(UserCenterResourse.AccountOption.PswAuthentication) == false) |
| | | { |
| | | //密码验证 |
| | | var form = new PswSecondarySecurityForm(); |
| | | form.AddForm(i_TouchText, i_PasswordText, i_GestureText, SuccessAction); |
| | | NotSettionAction = null; |
| | | } |
| | | else if (string.IsNullOrEmpty(UserCenterResourse.AccountOption.GestureAuthentication) == false) |
| | | { |
| | | //手势验证 |
| | | var form = new PswGestureSecirityForm(); |
| | | form.AddForm(i_TouchText, i_PasswordText, i_GestureText, SuccessAction); |
| | | NotSettionAction = null; |
| | | } |
| | | else |
| | | { |
| | | //完全没有设置有任何验证方式 |
| | | SuccessAction = null; |
| | | NotSettionAction?.Invoke(); |
| | | NotSettionAction = null; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |