示例#1
0
        /// <summary>
        /// 取得系统目录下的图片文件
        /// </summary>
        /// <param name="dirEnum"></param>
        /// <returns></returns>
        public static List <FileInfo> GetImagFiles(SystemDirecotry dirEnum)
        {
            if (!Directory.Exists(Globals.GetPath(dirEnum)))
            {
                return(new List <FileInfo>());
            }

            List <FileInfo> Files = GetImagFiles(Globals.GetPath(dirEnum), SearchOption.TopDirectoryOnly);

            if (Files != null && Files.Count > 0)
            {
                FileInfo file;
                for (int i = 0; i < Files.Count - 1; i++)
                {
                    for (int j = i + 1; j < Files.Count; j++)
                    {
                        if (Files[i].CreationTime < Files[j].CreationTime)
                        {
                            file     = Files[j];
                            Files[j] = Files[i];
                            Files[i] = file;
                        }
                    }
                }
            }

            return(Files);
        }
示例#2
0
        private bool ValidateAndSavePostedFile(AuthUser operatorUser, HttpPostedFile postedFile, string errorName, string extraFileSuffix, out string fullPath)
        {
            fullPath = string.Empty;
            if (postedFile == null)
            {
                ThrowError(new CustomError(errorName, "请上传身份证" + (extraFileSuffix == "face"?"正面":"背面") + "扫描件"));
                return(false);
            }

            List <string> allowedFileType = new List <string>(new string[] { ".jpg", ".png", ".gif" });

            byte[] data = new byte[postedFile.ContentLength];

            if (data.Length > AllSettings.Current.NameCheckSettings.MaxIDCardFileSize)
            {
                ThrowError(new CustomError(errorName, "身份证扫描件文件大小不能超过" + ConvertUtil.FormatSize(AllSettings.Current.NameCheckSettings.MaxIDCardFileSize)));
                return(false);
            }

            postedFile.InputStream.Read(data, 0, data.Length);

            string fileType = Path.GetExtension(postedFile.FileName).ToLower();

            if (!allowedFileType.Contains(fileType) || !IOUtil.IsImageFile(data, ImageFileType.GIF | ImageFileType.JPG | ImageFileType.PNG))
            {
                ThrowError(new CustomError(errorName, "身份证扫描件格式不正确"));
                return(false);
            }

            string newFileName = string.Format("{0}-{1}{2}", operatorUser.UserID, extraFileSuffix, ".config");
            string path        = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Upload_IDCard), operatorUser.UserID.ToString());

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path); //不做异常捕获
            }

            try
            {
                File.WriteAllBytes(IOUtil.JoinPath(path, newFileName), data);
            }
            catch (Exception ex)
            {
                ThrowError(new CustomError("发生了系统错误" + ex.Message));
                return(false);
            }

            fullPath = IOUtil.JoinPath(Globals.GetVirtualPath(SystemDirecotry.Upload_IDCard), operatorUser.UserID.ToString(), newFileName);

            return(true);
        }
示例#3
0
 private void DeleteEmoticonFiles(List <string> fileUrls)
 {
     foreach (string s in fileUrls)
     {
         if (s.Contains("/") || s.Contains("\\"))
         {
             IOUtil.DeleteFile(s);
         }
         else
         {
             string str = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Upload_Emoticons), s.Substring(0, 1), s.Substring(1, 1), s);
             IOUtil.DeleteFile(str);
         }
         IOUtil.DeleteFile(GetThumbFilePath(s, false));
     }
 }
示例#4
0
        public SpaceThemeCollection GetSpaceThemes()
        {
            string[]             dirs   = null;
            SpaceThemeCollection themes = new SpaceThemeCollection();

            SpaceTheme theme = new SpaceTheme();

            theme.Name = "默认风格";
            theme.Dir  = "default";
            themes.Add(theme);

            try
            {
                dirs = Directory.GetDirectories(Globals.GetPath(SystemDirecotry.SpaceStyles));                //.ApplicationPath + "max-templates/default\\theme");
            }
            catch
            {
                return(themes);
            }

            foreach (string dir in dirs)
            {
                string cssFilePath = IOUtil.JoinPath(dir, "style.css");

                if (File.Exists(cssFilePath) && File.Exists(IOUtil.JoinPath(dir, "preview.jpg")))
                {
                    string nameLine = IOUtil.ReadFirstLine(cssFilePath, Encoding.Default);

                    if (nameLine.StartsWith("/*") == false || nameLine.EndsWith("*/") == false)
                    {
                        continue;
                    }

                    DirectoryInfo dirInfo = new DirectoryInfo(dir);

                    theme      = new SpaceTheme();
                    theme.Name = nameLine.Substring(2, nameLine.Length - 4);
                    theme.Dir  = dirInfo.Name;

                    themes.Add(theme);
                }
            }

            return(themes);
        }
示例#5
0
        /// <summary>
        /// 存储由头像Flash上传的临时图片
        /// </summary>
        /// <param name="Request"></param>
        /// <param name="physicalFile">输出物理路径</param>
        /// <returns>返回临时文件的引用URL</returns>
        public string SaveTempAvatar(AuthUser operatorUser, HttpRequest Request, out string physicalFile)
        {
            if (operatorUser == User.Guest)
            {
                ThrowError(new NotLoginError());
                physicalFile = string.Empty;
                return(string.Empty);
            }

            if (Request.Files.Count == 0 || Request.FilePath.Length == 0)
            {
                throw new Exception("无法得到上传的文件");
            }

            HttpPostedFile avatarFile = Request.Files[0];

            string contentType = avatarFile.ContentType;

            string extendName = Path.GetExtension(avatarFile.FileName).ToLower();


            if (extendName != ".png" &&
                extendName != ".gif" &&
                extendName != ".jpg" &&
                extendName != ".jpeg" &&
                extendName != ".bmp")
            {
                throw new Exception("头像的文件扩展名不能是" + extendName);
            }

            string fileName = Guid.NewGuid().ToString("N") + extendName;

            string tempAvatarDirectory = Globals.GetPath(SystemDirecotry.Temp_Avatar);

            IOUtil.CreateDirectoryIfNotExists(tempAvatarDirectory);

            physicalFile = IOUtil.JoinPath(tempAvatarDirectory, fileName);

            avatarFile.SaveAs(physicalFile);

            return(Globals.GetVirtualPath(SystemDirecotry.Temp_Avatar, fileName));
        }
示例#6
0
        internal string GetThumbFilePath(string imageFilename, bool virtualPath)
        {
            string ThunmDir = "Thunmbnails";
            string fileName = Path.GetFileName(imageFilename);
            string path;

            fileName = fileName.Substring(0, fileName.LastIndexOf("."));
            if (virtualPath)
            {
                path = UrlUtil.JoinUrl(Globals.GetVirtualPath(SystemDirecotry.Upload_Emoticons), ThunmDir, fileName.Substring(0, 1), fileName.Substring(1, 1));
                return(string.Format("{0}/{1}.png", path, fileName));
            }
            else
            {
                path = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Upload_Emoticons), ThunmDir, fileName.Substring(0, 1), fileName.Substring(1, 1));
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                return(string.Format("{0}\\{1}.png", path, fileName));
            }
        }
示例#7
0
        private string BuildAvatarPath(int userID, bool isUnapprovedAvatar, UserAvatarSize?size, string extendName)
        {
            string sizeString;

            if (size == null)
            {
                sizeString = "{0}";
            }
            else
            {
                sizeString = GetAvatarSizeDirectoryName(size.Value);
            }

            if (isUnapprovedAvatar)
            {
                return(IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Upload_Avatar), Consts.User_UncheckAvatarSuffix, sizeString, GetAvatarLevel(userID, "\\", extendName)));
            }
            else
            {
                return(Globals.GetPath(SystemDirecotry.Upload_Avatar, sizeString, GetAvatarLevel(userID, "\\", extendName)));
            }
        }
示例#8
0
        public void UpdateSpaceTheme(string theme)
        {
            int userID = UserBO.Instance.GetCurrentUserID();

            if (string.Compare(theme, "default") == 0)
            {
                theme = string.Empty;
            }

            string path = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.SpaceStyles), theme);

            if (Directory.Exists(path))
            {
                SpaceDao.Instance.UpdateSpaceTheme(userID, theme);

                User user = UserBO.Instance.GetUserFromCache(userID);

                if (user != null)
                {
                    user.SpaceTheme = theme;
                }
            }
        }
示例#9
0
        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);
        }
示例#10
0
        public EmoticonSaveStatus SaveEmoticonFile(int userID, byte[] fileData, string md5, string fileName, out string relativeUrl)
        {
            Size thumbSize = new Size(AllSettings.Current.EmoticonSettings.ThumbImageWidth,
                                      AllSettings.Current.EmoticonSettings.ThumbImageHeight);

            relativeUrl = "";

            if (fileData != null && fileData.Length > 0)
            {
                //判断文件大小是否超出限制
                if (fileData.Length > MaxEmticonFileSize(userID))
                {
                    return(EmoticonSaveStatus.FileSizeOverflow);
                }

                if (!IsAllowedFileType(fileName))
                {
                    return(EmoticonSaveStatus.Failed);
                }

                string dirLevel1, dirLevel2;


                string filePostfix = ".gif"; //Path.GetExtension(fileName);

                fileName = string.Format("{0}_{1}{2}", md5, fileData.Length, filePostfix);

                string directory = Globals.GetPath(SystemDirecotry.Upload_Emoticons);

                dirLevel1 = md5.Substring(0, 1);
                dirLevel2 = md5.Substring(1, 1);

                directory = IOUtil.JoinPath(directory, dirLevel1, dirLevel2);

                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string filePath = IOUtil.JoinPath(directory, fileName);


                if (!File.Exists(filePath))
                {
                    using (FileStream fileStream = File.Create(filePath, fileData.Length))
                    {
                        fileStream.Write(fileData, 0, fileData.Length);
                        fileStream.Seek(0, SeekOrigin.Begin);

                        #region 生成缩略图
                        try
                        {
                            using (Bitmap bmpSource = new Bitmap(fileStream))
                            {
                                using (Bitmap bmp = new Bitmap(thumbSize.Width, thumbSize.Height))
                                {
                                    using (Graphics g = Graphics.FromImage(bmp))
                                    {
                                        g.Clear(Color.White);
                                        g.DrawImage(bmpSource, new Rectangle(0, 0, thumbSize.Width, thumbSize.Height));
                                        g.Save();
                                    }
                                    bmp.Save(GetThumbFilePath(filePath, false), ImageFormat.Png);
                                }
                            }
                        }
                        catch
                        {
                        }
                        #endregion

                        fileStream.Close();
                    }
                }
                relativeUrl = fileName;//直接返回文件名

                return(EmoticonSaveStatus.Success);
            }
            return(EmoticonSaveStatus.Failed);
        }
示例#11
0
        private string GetAvatarPhysicalPath(int userID, UserAvatarSize size, string src)
        {
            string t = UserBO.Instance.GetAvatarSizeDirectoryName(size);

            return(Globals.GetPath(SystemDirecotry.Upload_Avatar, t, src));
        }
示例#12
0
        //public string GetAvatarUrl(UserAvatarType type, int userID, string fileProfix, bool isChcech)
        //{
        //    if (StringUtil.StartsWith(fileProfix, '~'))
        //    {
        //        //int index = fileProfix.LastIndexOf("/");

        //        return fileProfix.Replace("{size}", type.ToString());
        //    }

        //    string url;

        //    GetAvatarPathAndUrl(type, userID, fileProfix, isChcech, false, false, out url);
        //    return url;
        //}

        //public string GetAvatarPhysicalPath(UserAvatarType type, int userID, string fileProfix, bool isChcech)
        //{
        //    string url;
        //    return GetAvatarPathAndUrl(type, userID, fileProfix, isChcech, true, true, out url);
        //}

        //public string GetAvatarPath(UserAvatarType type, int userID, string fileProfix, bool isCheched, out string virtualPath)
        //{
        //    return GetAvatarPathAndUrl(type, userID, fileProfix, isCheched, false, true, out virtualPath);
        //}

        //private string GetAvatarPathAndUrl(UserAvatarType type, int userID, string fileProfix, bool isCheched, bool createDirectory, bool getPhysicsPath, out string virtualPath)
        //{
        //    if (fileProfix.Length > 4)
        //    {
        //        virtualPath = string.Empty;
        //        return string.Empty;
        //    }

        //    if (string.IsNullOrEmpty(fileProfix))
        //    {
        //        fileProfix = ".jpg";
        //    }
        //    else
        //    {
        //        if (!StringUtil.StartsWith(fileProfix, '.'))
        //        {
        //            fileProfix = "." + fileProfix;
        //        }
        //    }

        //    string fileName = userID + fileProfix;
        //    string pathLevel = GetUserAvatarPathLevel(userID);

        //    string temp1 = IOUtil.JoinPath(isCheched ? string.Empty : Consts.User_UncheckAvatarSuffix, type.ToString(), pathLevel);

        //    virtualPath = UrlUtil.JoinUrl(Globals.GetRelativeUrl(SystemDirecotry.Upload_Avatar), temp1, fileName);

        //    if (getPhysicsPath || createDirectory)
        //    {
        //        string dir = IOUtil.JoinPath(Globals.GetPath(SystemDirecotry.Upload_Avatar), temp1);
        //        if (createDirectory) IOUtil.CreateDirectory(dir);

        //        if (getPhysicsPath) return IOUtil.JoinPath(dir, fileName);
        //    }

        //    return string.Empty;
        //}

        /// <summary>
        /// 验证用户临时头像
        /// </summary>
        /// <param name="operatorUserID"></param>
        /// <param name="targetUserIds"></param>
        /// <param name="isChecked"></param>
        public void CheckUserAvatar(AuthUser operatorUser, IEnumerable <int> targetUserIds, bool isChecked)
        {
            if (!CanAvatarCheck(operatorUser))
            {
                ThrowError(new NoPermissionEditUserProfileError());
                return;
            }

            UserTempAvatarCollection tempAvatarDatas = UserTempAvatarDao.Instance.GetUserTempAvatars(targetUserIds);
            string defaultDir = GetAvatarSizeDirectoryName(UserAvatarSize.Default);
            string bigDir     = GetAvatarSizeDirectoryName(UserAvatarSize.Big);
            string smallDir   = GetAvatarSizeDirectoryName(UserAvatarSize.Small);

            foreach (UserTempAvatar ta in tempAvatarDatas)
            {
#if !DEBUG
                try
                {
#endif
                if (isChecked)//审核通过
                {
                    if (!string.IsNullOrEmpty(ta.CurrentAvatar))
                    {
                        IOUtil.DeleteFile(GetAvatarPhysicalPath(ta.UserID, UserAvatarSize.Small, ta.CurrentAvatar));
                        IOUtil.DeleteFile(GetAvatarPhysicalPath(ta.UserID, UserAvatarSize.Default, ta.CurrentAvatar));
                        IOUtil.DeleteFile(GetAvatarPhysicalPath(ta.UserID, UserAvatarSize.Big, ta.CurrentAvatar));
                    }

                    string newFileType  = Path.GetExtension(ta.TempAvatar);
                    string newAvatarSrc = GetAvatarLevel(ta.UserID, "/", newFileType);
                    string newFilePath  = Globals.GetPath(SystemDirecotry.Upload_Avatar, "{0}", newAvatarSrc);


                    IOUtil.MoveFile(IOUtil.MapPath(string.Format(ta.TempAvatar, smallDir))
                                    , string.Format(newFilePath, smallDir));

                    IOUtil.MoveFile(IOUtil.MapPath(string.Format(ta.TempAvatar, defaultDir))
                                    , string.Format(newFilePath, defaultDir));

                    IOUtil.MoveFile(IOUtil.MapPath(string.Format(ta.TempAvatar, bigDir))
                                    , string.Format(newFilePath, bigDir));

                    User u = UserBO.Instance.GetUser(ta.UserID);
                    u.AvatarSrc = newAvatarSrc;
                    if (OnUserAvatarChanged != null)
                    {
                        OnUserAvatarChanged(u.UserID, u.AvatarSrc, u.SmallAvatarPath, u.AvatarPath, u.BigAvatarPath);
                    }
                    UserDao.Instance.UpdateAvatar(u.UserID, u.AvatarPropFlag.GetStringForSave(), true);
                }
                else //未审核通过
                {
                    IOUtil.DeleteFile(IOUtil.MapPath(string.Format(ta.TempAvatar, defaultDir)));
                    IOUtil.DeleteFile(IOUtil.MapPath(string.Format(ta.TempAvatar, bigDir)));
                    IOUtil.DeleteFile(IOUtil.MapPath(string.Format(ta.TempAvatar, smallDir)));
                }
#if !DEBUG
            }
            catch
            {
            }
#endif
            }
            UserTempDataBO.Instance.Delete(targetUserIds, UserTempDataType.Avatar);
        }