Exemplo n.º 1
0
        /// <summary>
        /// 创建首页
        /// </summary>
        /// <returns></returns>
        public static void GreateIndexPage()
        {
            TemplateHelper h         = new TemplateHelper();
            SysSetting     setting   = BasePage.SystemSetting;
            string         IndexFile = "~/" + setting.ClassFolder + "/index" + setting.ExtName;


            Voodoo.IO.File.Write(System.Web.HttpContext.Current.Server.MapPath(IndexFile), h.GetIndex());

            ping(BasePage.SystemSetting.SiteUrl);

            CreatePagesByCrateWith(1);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file"></param>
        /// <param name="ClassID"></param>
        /// <returns></returns>
        public static Result UpLoadFile(HttpPostedFile file, int ClassID)
        {
            Result     r  = new Result();
            SysSetting ss = BasePage.SystemSetting;

            string FileName = file.FileName.GetFileNameFromPath();    //文件名
            string ExtName  = file.FileName.GetFileExtNameFromPath(); //扩展名
            string NewName  = @string.GetGuid() + ExtName;            //新文件名

            if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(',')))
            {
                r.Success = false;
                r.Text    = "不允许上传此类文件";
                return(r);
            }
            if (file.ContentLength > ss.MaxPostFileSize)
            {
                r.Success = false;
                r.Text    = "文件太大";
                return(r);
            }

            string Folder        = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; //文件目录
            string FolderShotCut = Folder + "ShortCut/";                                         //缩略图目录

            string FilePath          = Folder + NewName;                                         //文件路径
            string FilePath_ShortCut = FolderShotCut + NewName;                                  //缩略图路径

            file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(FilePath), true);

            File f = new File();

            if (ExtName.ToLower().Replace(".", "").IsInArray("jpg,jpeg,png,gif,bmp".Split(',')))
            {
                ImageHelper.MakeThumbnail(System.Web.HttpContext.Current.Server.MapPath(FilePath), System.Web.HttpContext.Current.Server.MapPath(FilePath_ShortCut), 105, 118, "Cut");
            }
            else
            {
                FilePath_ShortCut = "";
                f.FileType        = 1;
            }
            FileInfo savedFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(FilePath));



            f.FileDirectory = ss.FileDir;
            f.FileExtName   = ExtName;
            f.FilePath      = FilePath;
            f.FileSize      = (savedFile.Length / 1024).ToInt32();
            //f.FileType=
            f.SmallPath = FilePath_ShortCut;
            f.UpTime    = DateTime.Now;

            using (DataEntities ent = new DataEntities())
            {
                ent.AddToFile(f);
                ent.SaveChanges();
            }
            //FileView.Insert(f);

            r.Success = true;
            r.Text    = FilePath;
            return(r);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public Result UserRegister(User user)
        {
            SysSetting setting = BasePage.SystemSetting;

            Result r = new Result();

            if (!setting.EnableReg)//不允许注册
            {
                r.Success = false;
                r.Text    = "系统关闭了用户注册功能!";
                return(r);
            }

            if (UserView.Exist(string.Format("UserName='******'", user.UserName)))
            {
                r.Success = false;
                r.Text    = "这个账号已经存在,请重新选择!";
                return(r);
            }

            if (user.UserName.Length > setting.MaxUserName || user.UserName.Length < setting.MinUserName)
            {
                r.Success = false;
                r.Text    = string.Format("账号长度请设置在{0}和{1}之间", setting.MinUserName, setting.MaxUserName);
                return(r);
            }

            //密码经过MD5加密后无法验证长度

            //系统保留词
            string[] userNameFilter = setting.UserNameFilter.Trim().Split(',');
            foreach (string k in userNameFilter)
            {
                if (user.UserName.Contains(k))
                {
                    r.Success = false;
                    r.Text    = "账号中存在系统保留词,请重新设置";
                    return(r);
                }
            }

            if (setting.EmailCheck)
            {
                if (UserView.Exist(string.Format("Email='{0}'", user.Email)))
                {
                    r.Success = false;
                    r.Text    = "您设置的邮箱账号已经在系统中注册,系统不允许重复注册";
                    return(r);
                }
            }

            //用户默认分组
            if (user.Group <= 0)
            {
                user.Group = setting.RegisterDefaultGroup;
            }

            UserGroup g = UserGroupView.GetModelByID(user.Group.ToS());

            user.Enable = g.RegAutoAudit;

            //注册时间间隔
            user.RegIP = WS.GetIP();
            var ipusers = UserView.GetModelList(string.Format("RegIP='{0}'", user.RegIP)).OrderByDescending(p => p.RegTime);

            if (ipusers.Count() > 0)
            {
                User _lastUser = ipusers.First();

                if (_lastUser != null && (DateTime.Now - _lastUser.RegTime).TotalMinutes < Convert.ToDouble(setting.RegTimeSpan.ToDecimal()))
                {
                    r.Success = false;
                    r.Text    = "您的注册动作过于频繁,请稍后重试!";
                    return(r);
                }
            }
            user.RegTime       = DateTime.Now;
            user.Cent          = setting.RegCent;
            user.LastLoginIP   = WS.GetIP();
            user.LastLoginTime = DateTime.Now;

            UserView.Insert(user);
            r.Success = true;
            r.Text    = "注册成功!";
            return(r);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <param name="ClassID"></param>
        /// <returns></returns>
        public static Result UpLoadImage(HttpPostedFile file, int ImageAlbumID)
        {
            Result     r  = new Result();
            SysSetting ss = BasePage.SystemSetting;

            string FileName = file.FileName.GetFileNameFromPath().ToLower();    //文件名
            string ExtName  = file.FileName.GetFileExtNameFromPath().ToLower(); //扩展名
            string NewName  = @string.GetGuid() + ExtName;                      //新文件名

            if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(',')))
            {
                r.Success = false;
                r.Text    = "不允许上传此类文件";
                return(r);
            }
            if (file.ContentLength > ss.MaxPostFileSize)
            {
                r.Success = false;
                r.Text    = "文件太大";
                return(r);
            }

            string Folder        = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; //文件目录
            string FolderShotCut = Folder + "ShortCut/";                                         //缩略图目录

            string FilePath          = Folder + NewName;                                         //文件路径
            string FilePath_ShortCut = FolderShotCut + NewName;                                  //缩略图路径

            file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(FilePath), true);


            if (ExtName.ToLower().Replace(".", "").IsInArray("jpg,jpeg,png,gif,bmp".Split(',')))
            {
                ImageHelper.MakeThumbnail(System.Web.HttpContext.Current.Server.MapPath(FilePath), System.Web.HttpContext.Current.Server.MapPath(FilePath_ShortCut), 105, 118, "Cut");
            }

            ImageAlbum album = ImageAlbumView.GetModelByID(ImageAlbumID.ToS());

            Images img = new Images();

            img.AlbumID    = album.ID;
            img.ClickCount = 0;
            img.ExtName    = ExtName;
            img.FilePath   = FilePath;
            img.FileSize   = file.ContentLength;
            img.Intro      = "";
            img.ReplyCount = 0;
            img.SmallPath  = FilePath_ShortCut;
            img.Title      = "";
            img.UploadTime = DateTime.Now;
            ImagesView.Insert(img);

            ImageAlbum imga = ImageAlbumView.GetModelByID(ImageAlbumID.ToString());

            imga.Size = ImagesView.Count(string.Format("AlbumID={0}", imga.ID));
            ImageAlbumView.Update(imga);

            r.Success = true;
            r.Text    = FilePath;
            return(r);
        }