protected void Page_Load(object sender, EventArgs e) { bool isFaceFile = _Request.Get <bool>("face", Method.Get, false); int userID = _Request.Get <int>("userid", Method.Get, 0); AuthenticUser user = UserBO.Instance.GetAuthenticUserInfo(My, userID); if (user != null) { string filePath; if (isFaceFile) { filePath = user.IDCardFileFace; } else { filePath = user.IDCardFileBack; } if (user.HasIDCardFileFace) { string path = Globals.GetPath(SystemDirecotry.Root, filePath); if (File.Exists(path)) { string filename = user.Realname + ".jpg"; if (Request.Headers["Accept-Charset"] == null) { filename = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes(filename)).Replace("+", "%20"); } FileInfo file = new FileInfo(path); Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream"; //Response.AppendHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode(user.Realname + ".jpg", System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Disposition", "inline;filename=" + filename); Response.AppendHeader("Content-Length", file.Length.ToString()); Response.TransmitFile(filePath); Response.Flush(); return; } else { Response.ClearContent(); Response.Write("文件不存在:" + filePath); Response.End(); } } } else { Response.ClearContent(); Response.Write("用户不存在"); Response.End(); } }
/// <summary> /// 实名认证 /// </summary> /// <param name="targetUserIds"></param> /// <param name="realnameChecked">是否</param> public void AdminSetRealnameChaecked(AuthUser operatorUser, int targetUserId, bool realnameChecked, string remark, bool sendNotify) { if (operatorUser == User.Guest) { ThrowError(new NotLoginError()); return; } if (!CanRealnameCheck(operatorUser)) { ThrowError(new NoPermissionRealnameCheckError()); return; } UserDao.Instance.SetRealnameChecked(operatorUser.UserID, targetUserId, realnameChecked, remark); if (sendNotify) { string content = realnameChecked ? "恭喜您已通过实名认证" : "您的实名认证被拒绝," + (!string.IsNullOrEmpty(remark) ? "原因:" + StringUtil.CutString(remark, 100) : ""); AdminManageNotify notify = new AdminManageNotify(targetUserId, content); notify.UserID = targetUserId; NotifyBO.Instance.AddNotify(operatorUser, notify); } RemoveUserCache(targetUserId); if (realnameChecked) { if (OnUserRealnameChecked != null) { AuthenticUser authenticUserInfo = GetAuthenticUserInfo(operatorUser, targetUserId); if (authenticUserInfo != null) { OnUserRealnameChecked(targetUserId, authenticUserInfo.Realname, authenticUserInfo.IDNumber); } else { AuthUser user = GetAuthUser(targetUserId); if (user != null) { OnUserRealnameChecked(targetUserId, user.Realname, string.Empty); } } } } else { if (OnUserCancelRealnameCheck != null) { OnUserCancelRealnameCheck(targetUserId); } } }
public int DetectAuthenticInfo(AuthUser operatorUser, int userID, out List <string> photos) { photos = null; if (operatorUser.UserID <= 0) { ThrowError(new NotLoginError()); return(4); } if (!CanRealnameCheck(operatorUser)) { ThrowError(new NoPermissionRealnameCheckError()); return(4); } AuthenticUser userInfo = GetAuthenticUserInfo(operatorUser, userID); if (userInfo == null) { ThrowError(new CustomError("没有该用户提交的实名认证材料")); return(4); } List <byte[]> photoData; int state = DetectAuthenticInfo(userInfo.Realname, userInfo.IDNumber, out photoData); if (state == 0) { photos = new List <string>(); if (photoData != null) { string photoString = ""; string temp; string photoDirName = "Photos"; string photoPath = Globals.GetPath(SystemDirecotry.Upload_IDCard, photoDirName); string virtualPath = Globals.GetVirtualPath(SystemDirecotry.Upload_IDCard, photoDirName); if (!Directory.Exists(photoPath)) { Directory.CreateDirectory(photoPath); } for (int i = 0; i < photoData.Count; i++) { string fileName = string.Format("{0}_{1}.jpg", userInfo.IDNumber, i); if (photoString.Length > 0) { photoString += "|"; } temp = UrlUtil.JoinUrl(virtualPath, fileName); photoString += temp; photos.Add(temp); fileName = IOUtil.JoinPath(photoPath, fileName); if (!File.Exists(fileName)) { File.WriteAllBytes(fileName, photoData[i]); } if (photos.Count > 1) //多余的照片不要, 只要最多两张 { break; } } UserDao.Instance.UpdateAuthenticUserPhoto(userID, photoString, state); } } return(state); }
/// <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); }