Ejemplo n.º 1
0
 private static string Join(JoinType joinType, params string[] paths)
 {
     if (joinType == JoinType.Path)
     {
         return(IOUtil.JoinPath(paths));
     }
     else if (joinType == JoinType.Url)
     {
         return(UrlUtil.JoinUrl(paths));
     }
     else if (joinType == JoinType.RelativeUrl)
     {
         string temp = UrlUtil.JoinUrl(paths);
         return(StringUtil.StartsWith(temp, '/') ? "~" + temp : "~/" + temp);
     }
     return(string.Empty);
 }
Ejemplo n.º 2
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));
            }
        }
Ejemplo n.º 3
0
        private string BuildAvatarVirtualPath(int userID, bool isUnapprovedAvatar, UserAvatarSize?size, string extendName)
        {
            string sizeString;

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

            if (isUnapprovedAvatar)
            {
                return(UrlUtil.JoinUrl(Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar), Consts.User_UncheckAvatarSuffix, sizeString, GetAvatarLevel(userID, "/", extendName)));
            }
            else
            {
                return(Globals.GetPath(SystemDirecotry.Upload_Avatar, sizeString, GetAvatarLevel(userID, "/", extendName)));
            }
        }
Ejemplo n.º 4
0
 private static string Join(JoinType joinType, string str1, string str2, string str3)
 {
     if (joinType == JoinType.Path)
     {
         return(IOUtil.JoinPath(str1, str2, str3));
     }
     else if (joinType == JoinType.Url)
     {
         return(UrlUtil.JoinUrl(str1, str2, str3));
     }
     else if (joinType == JoinType.RelativeUrl)
     {
         if (StringUtil.StartsWith(str1, '/'))
         {
             return(UrlUtil.JoinUrl("~", str1, str2, str3));
         }
         else
         {
             return(UrlUtil.JoinUrl("~/", str1, str2, str3));
         }
     }
     return(string.Empty);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 返回指定系统目录的虚拟路径
        /// </summary>
        /// <param name="systemDirecotry"></param>
        /// <returns></returns>
        public static string GetVirtualPath(SystemDirecotry systemDirecotry, string addPath1, string addPath2)
        {
            string basePath = GetPath(JoinType.Url, s_AppRoot, systemDirecotry);

            return(UrlUtil.JoinUrl(basePath, addPath1, addPath2));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 返回带~的虚拟路径
        /// </summary>
        /// <param name="direcotry"></param>
        /// <returns></returns>
        public static string GetRelativeUrl(SystemDirecotry direcotry, string addPath1, string addPath2)
        {
            string basePath = GetPath(JoinType.RelativeUrl, string.Empty, direcotry);

            return(UrlUtil.JoinUrl(basePath, addPath1, addPath2));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private string BuildThumb(PhysicalFileFromTemp file)
        {
            return(string.Empty);

            string thumbPathRoot = IOUtil.ResolvePath(ThumbRoot);
            string extendName    = Path.GetExtension(file.TempUploadFileName);

            string level1 = file.MD5.Substring(0, 1);
            string level2 = file.MD5.Substring(1, 1);
            string level3 = file.MD5.Substring(2, 1);

            extendName = extendName.ToLower();

            string thumbFilename = string.Format("{0}_{1}.png", file.MD5, file.FileSize);
            string dir           = IOUtil.JoinPath(thumbPathRoot, level1, level2, level3);

            try
            {
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            catch
            {
                return(string.Empty);
            }

            string thumbFilePath = IOUtil.JoinPath(thumbPathRoot, level1, level2, level3, thumbFilename);
            string thumbUrl      = UrlUtil.JoinUrl(ThumbRoot, level1, level2, level3, thumbFilename);

            switch (extendName)
            {
            case ".jpg":
            case ".jpge":
            case ".bmp":
            case ".png":
            case ".gif":

                Image img = null, imgThumb = null;
                try
                {
                    img = Bitmap.FromFile(file.PhysicalFilePath);
                }
                catch    // (Exception ex)
                {
                    return(string.Empty);
                }

                using (imgThumb = new Bitmap(ThumbSize, ThumbSize))
                {
                    int   x, y, w, h;
                    float scale = (float)img.Width / (float)img.Height;
                    if (img.Width > img.Height)
                    {
                        x = 0; w = ThumbSize;
                        h = (int)((float)w / scale);
                        y = (ThumbSize - h) / 2;
                    }
                    else if (img.Width == img.Height)
                    {
                        x = 0;
                        y = 0;
                        w = ThumbSize;
                        h = ThumbSize;
                    }
                    else
                    {
                        y = 0;
                        h = ThumbSize;
                        w = (int)((float)ThumbSize * scale);
                        x = (ThumbSize - w) / 2;
                    }

                    using (Graphics g = Graphics.FromImage(imgThumb))
                    {
                        g.Clear(Color.White);
                        g.DrawImage(img, new Rectangle(x, y, w, h), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
                        g.Save();
                    }
                    try
                    {
                        img.Save(thumbFilePath, System.Drawing.Imaging.ImageFormat.Png);
                    }
                    catch
                    {
                        return(string.Empty);
                    }
                }
                img.Dispose();
                return(thumbUrl);

            default:
                break;
            }

            return(string.Empty);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 处理由头像Flash上传的已经截取好的图片(三个尺寸)
        /// </summary>
        /// <param name="Request"></param>
        public void SaveAvatar(AuthUser operatorUser, int targetUserID, HttpRequest request)
        {
            if (operatorUser == User.Guest)
            {
                ThrowError(new NotLoginError());
                return;
            }

            if (operatorUser.UserID != targetUserID)
            {
                if (!CanEditUserAvatar(operatorUser, targetUserID))
                {
                    return;
                }
            }

            string tempFilename = request.QueryString["file"];

            string extendName = Path.GetExtension(tempFilename).ToLower();

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

            uint length    = 0;
            int  lastIndex = 0;

            byte[] data = request.BinaryRead(request.TotalBytes);
            byte[] avatarData, dataLength, sizeArray;

            int            sizeIndex = 0;
            UserAvatarSize avatarSize;

            dataLength = new byte[4];
            sizeArray  = StringUtil.Split <byte>(request.Headers["size"]);

            bool isUnappreved;

            //如果开启了头像审查,且操作者没有审查头像的权限,那么头像就应该是未审核状态
            if (AllSettings.Current.AvatarSettings.EnableAvatarCheck
                &&
                CanAvatarCheck(operatorUser) == false)
            {
                isUnappreved = true;
            }
            else
            {
                isUnappreved = false;
            }

            //同时上传3个尺寸的头像。 分割数据
            while (lastIndex < data.Length)
            {
                dataLength[0] = data[lastIndex];
                dataLength[1] = data[lastIndex + 1];
                dataLength[2] = data[lastIndex + 2];
                dataLength[3] = data[lastIndex + 3];

                Array.Reverse(dataLength);
                length     = BitConverter.ToUInt32(dataLength, 0);
                lastIndex += 4;
                avatarData = new byte[length];
                for (int i = 0; i < length; i++)
                {
                    avatarData[i] = data[lastIndex + i];
                }
                lastIndex += (int)length;

                if (sizeArray[sizeIndex] == 24)
                {
                    avatarSize = UserAvatarSize.Small;
                }
                else if (sizeArray[sizeIndex] == 120)
                {
                    avatarSize = UserAvatarSize.Big;
                }
                else
                {
                    avatarSize = UserAvatarSize.Default;
                }


                string savePath = BuildAvatarPath(targetUserID, isUnappreved, avatarSize, extendName);

                IOUtil.CreateDirectoryIfNotExists(Path.GetDirectoryName(savePath));

                using (FileStream file = new FileStream(savePath, FileMode.Create))
                {
                    file.Write(avatarData, 0, avatarData.Length);
                }

                //UploadAvatar(operatorUser, targetUserID, temp, avatarType, extendName);

                sizeIndex++;
            }

            #region 对用户进行积分操作

            if (isUnappreved)
            {
                string savePath = UrlUtil.JoinUrl(Globals.GetVirtualPath(SystemDirecotry.Upload_Avatar), Consts.User_UncheckAvatarSuffix, "{0}", GetAvatarLevel(targetUserID, "\\", extendName));

                UserTempDataBO.Instance.SaveData(targetUserID, UserTempDataType.Avatar, savePath, true);
            }
            else
            {
                AuthUser user = GetAuthUser(targetUserID, true);

                string savePath = GetAvatarLevel(targetUserID, "/", extendName);
                user.AvatarPropFlag.OriginalData = savePath;
                UserDao.Instance.UpdateAvatar(targetUserID, user.AvatarPropFlag.GetStringForSave(), true);
                //RemoveUserCache(targetUserID);

                user.AvatarSrc = savePath;
                user.ClearAvatarCache();

                if (OnUserAvatarChanged != null)
                {
                    string smallAvatarPath   = UrlUtil.JoinUrl(Globals.SiteRoot, user.SmallAvatarPath);
                    string defaultAvatarPath = UrlUtil.JoinUrl(Globals.SiteRoot, user.AvatarPath);
                    string bigAvatarPath     = UrlUtil.JoinUrl(Globals.SiteRoot, user.BigAvatarPath);
                    OnUserAvatarChanged(targetUserID, savePath, smallAvatarPath, defaultAvatarPath, bigAvatarPath);
                }
            }

            #endregion


            if (tempFilename.StartsWith(Globals.GetVirtualPath(SystemDirecotry.Temp_Avatar), StringComparison.OrdinalIgnoreCase))
            {
                IOUtil.DeleteFile(tempFilename); //删除用户制作头像时上传的临时文件
            }
        }