Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="idCardImage"></param>
        public bool SaveUserRealnameData(AuthUser operatorUser, string idNumber, string realname, HttpPostedFile idCardFileFace, HttpPostedFile idCardFileBack)
        {
            if (operatorUser.UserID <= 0)
            {
                ThrowError(new NotLoginError());
                return(false);
            }

            if (!AllSettings.Current.NameCheckSettings.EnableRealnameCheck)
            {
                ThrowError(new CustomError("管理员未开启实名认证功能"));
                return(false);
            }

            if (UserDao.Instance.CheckIdNumberExist(idNumber))
            {
                ThrowError(new CustomError("idnumber", "您输入的身份证号码已经存在"));
                return(false);
            }

            AuthenticUser AuthenticUser = UserDao.Instance.GetAuthenticUser(operatorUser.UserID);

            if (AuthenticUser != null)
            {
                if (AuthenticUser.Processed == false)
                {
                    ThrowError(new CustomError("您的实名认证材料正在审核中请勿重复提交"));
                    return(false);
                }

                if (AuthenticUser.Processed == true && operatorUser.RealnameChecked)
                {
                    ThrowError(new CustomError("您已经通过实名认证, 不可再更改身份信息"));
                    return(false);
                }
            }

            realname = (string.Empty + realname).Trim();

            if (realname.Length < 2 || realname.Length > 15)
            {
                ThrowError(new CustomError("realname", "姓名不能少于2个字符并且不能超过15个字符"));
                return(false);
            }

            #region  中英文格式检查

            ////中文检查
            //bool formatchecked = false;
            //if (setting.CanChinese)
            //{
            //    if (Regex.IsMatch(realname, (@"^[\u4e00-\u9fa5\s]{2,8}$")))
            //    {
            //        formatchecked = true;
            //    }
            //}

            ////英文检查
            //if (setting.CanEnglish)
            //{
            //    if (Regex.IsMatch(realname, @"^[a-zA-Z]+\s{0,1}[a-zA-Z]+$"))
            //    {
            //        formatchecked = true;
            //    }
            //}

            //if (!setting.CanEnglish &&
            //    !setting.CanChinese &&
            //    !string.IsNullOrEmpty(realname)
            //   )
            //{
            //    //两种都不行 设置上 疏忽了, 那就没有限制
            //    formatchecked = true;
            //}

            //if (!formatchecked)
            //{
            //    ThrowError(new RealnameFormatError(realname, setting.CanChinese, setting.CanEnglish));
            //    return;
            //}

            #endregion

            if (!Regex.IsMatch(realname, (@"^[\u4e00-\u9fa5\s]{2,15}$")))
            {
                ThrowError(new CustomError("realname", "您输入的真实姓名包含无效的非中文字符"));
                return(false);
            }

            string[] idCardInfo;

            if (!IsIDCardNumber(idNumber, out idCardInfo))
            {
                ThrowError(new CustomError("idnumber", "身份证号码无效"));
                return(false);
            }

            string fullPathFace = string.Empty, fullPathBack = string.Empty;
            if (AllSettings.Current.NameCheckSettings.NeedIDCardFile)
            {
                bool saveFaceFile = true;
                bool saveBackFile = true;

                saveFaceFile = ValidateAndSavePostedFile(operatorUser, idCardFileFace, "idcardfileface", "face", out fullPathFace);
                saveBackFile = ValidateAndSavePostedFile(operatorUser, idCardFileBack, "idcardfileback", "back", out fullPathBack);

                if (saveBackFile == false || saveFaceFile == false)
                {
                    return(false);
                }
            }

            Gender   gender   = StringUtil.TryParse <Gender>(idCardInfo[0]);
            DateTime birthday = StringUtil.TryParse <DateTime>(idCardInfo[1]);

            UserDao.Instance.SaveAuthenticUserInfo(operatorUser.UserID, realname, idNumber, fullPathFace, fullPathBack, birthday, gender, idCardInfo[2]);
            return(true);
        }