public ActionResult AddPicCls(HttpPostedFileBase CoverFile, PictureClass picCls)
        {
            string account = Server.HtmlEncode(Request.Cookies["Accout"].Value);

            if (CoverFile != null)
            {
                FileInfo fi = new FileInfo(CoverFile.FileName);
                string   hz = fi.Extension;

                string time = DateTime.Now.ToString("yyyyMMddHHmmssffffff");

                if (CoverFile.ContentLength > 0 && hz == ".jpg" || hz == ".gif" || hz == ".png" || hz == ".jpeg")
                {
                    CoverFile.SaveAs(Server.MapPath("~/UploadPicture/PictureClsCover/" + time + hz));

                    picCls.picClsCreateTime = DateTime.Now;
                    picCls.uAccount         = account;

                    picCls.CoverFile = "/UploadPicture/PictureClsCover/" + time + hz;
                    db.PictureClass.Add(picCls);
                    db.SaveChanges();
                }
                else
                {
                    return(Content("<script>alert('SORRY!!!上传失败!!!请用.jpg/.jpeg/.gif/.png的照片上传。');history.go(-1);</script>"));
                }
            }
            return(RedirectToAction("index", "mypicture"));
        }
        //添加文章评论
        public ActionResult AddArtcm(ArtComment cm, string uAccout)
        {
            if (uAccout != "")
            {
                cm.uAccount        = uAccout;
                cm.artCmCreateTime = DateTime.Now;
                db.ArtComment.Add(cm);
                db.SaveChanges();
            }
            else
            {
                cm.artCmCreateTime = DateTime.Now;
                cm.uAccount        = "cyan";
                db.ArtComment.Add(cm);
                db.SaveChanges();
            }

            var         acm     = db.ArtComment.Where(c => c.artID == cm.artID).ToList();
            int         artcmcn = acm.Count;
            ArticleInfo ai      = db.ArticleInfo.Find(cm.artID);

            ai.artComCnt = artcmcn;
            db.SaveChanges();

            var obj = new
            {
                ok = "true"
            };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
        public ActionResult UpdateInfo(string nickname, string gender, string describe, string introduce)
        {
            string account = Server.HtmlEncode(Request.Cookies["Accout"].Value);

            if (nickname != "")
            {
                if (describe.Length <= 150 && introduce.Length <= 150)
                {
                    using (StoryBlog_DBEntities db = new StoryBlog_DBEntities())
                    {
                        var user = db.UserInfo.Where(u => u.Account == account);
                        user.FirstOrDefault().NickName  = nickname;
                        user.FirstOrDefault().Gender    = gender;
                        user.FirstOrDefault().Introduce = introduce;
                        user.FirstOrDefault().Describe  = describe;
                        db.SaveChanges();
                    }
                    Session["User"] = nickname;

                    ViewBag.Info = "您的昵称已修改为" + nickname + ",资料信息亦更新成功!";
                }
                else
                {
                    ViewBag.Info4 = "SORRY!!!自我介绍或个人描述的字数已超过了150字!!!";
                }
            }
            else
            {
                ViewBag.Info4 = "SORRY!!!昵称不能为空!!!";
            }

            return(View());
        }
        public ActionResult Index(UserInfo userinfo, string Account)
        {
            //提交登录信息,判断账号和密码是否合法
            if (ModelState.IsValid && Shujuyanzheng(userinfo.Account, userinfo.PassWord))
            {
                var Luser = db.UserInfo.Where(n => n.Account == Account).FirstOrDefault();

                //跟新数据库的登录时间
                Luser.LoginTime = DateTime.Now;

                db.SaveChanges();

                //定义cookies,接受数据库的值并保存到客户端
                Response.Cookies["User"].Value   = Luser.NickName;
                Response.Cookies["Accout"].Value = Luser.Account;
                Response.Cookies["ID"].Value     = Luser.ID.ToString();

                //接受前端的值,判断是否七天免登录
                if (Request["ckif"] != null)
                {
                    Response.Cookies["User"].Expires   = DateTime.Now.AddDays(7);
                    Response.Cookies["Accout"].Expires = DateTime.Now.AddDays(7);
                    Response.Cookies["ID"].Expires     = DateTime.Now.AddDays(7);
                }
                else
                {
                    Response.Cookies["User"].Expires   = DateTime.Now.AddHours(2);
                    Response.Cookies["Accout"].Expires = DateTime.Now.AddHours(2);
                    Response.Cookies["ID"].Expires     = DateTime.Now.AddHours(2);
                }

                //Session["User"] = Server.HtmlEncode(Request.Cookies["User"].Value);
                //Session["Accout"] = Server.HtmlEncode(Request.Cookies["Accout"].Value);
                //Session["ID"] = Server.HtmlEncode(Request.Cookies["ID"].Value);

                //根据接受url的值,判断跳转的页面;
                if (flag == "myp")
                {
                    return(RedirectToAction("index", "mypicture"));
                }
                else if (flag == "per")
                {
                    return(RedirectToAction("index", "personalblog"));
                }
                else if (flag == "mya")
                {
                    return(RedirectToAction("index", "myarticle"));
                }
                else
                {
                    return(RedirectToAction("index", "Home"));
                }
            }
            else
            {
                ViewBag.yanzheng = "用户名或密码错误";
                return(View());
            }
        }
        public ActionResult ArtDel(string id)
        {
            ArticleInfo ai = db.ArticleInfo.Where(a => a.artNo == id).FirstOrDefault();
            //删除文章的评论
            var        cm  = db.ArtComment.Where(c => c.artID == ai.ID).ToList();
            ArtComment acm = new ArtComment();

            foreach (var item in cm)
            {
                acm = db.ArtComment.Find(item.ID);
                db.ArtComment.Remove(acm);
            }

            db.ArticleInfo.Remove(ai);
            db.SaveChanges();
            return(RedirectToAction("index", "PersonalBlog"));
        }
        //浏览文章
        public ActionResult SelectArt(string id)
        {
            string account;
            string aid = id;

            try
            {
                //account = System.Web.HttpContext.Current.Session["Accout"].ToString();
                account = Server.HtmlEncode(Request.Cookies["Accout"].Value);
                if (account != null)
                {
                    var user = db.UserInfo.Where(u => u.Account == account);
                    ViewBag.picture = user.FirstOrDefault().Picture;
                }
            }
            catch (Exception)
            {
                account = null;
            }
            finally
            {
                artider = id;
                ArticleInfo arti = db.ArticleInfo.Where(a => a.artNo == aid).FirstOrDefault();
                arti.artHot = arti.artHot + 1;
                db.SaveChanges();


                var art = (from i in db.ArticleInfo
                           join u in db.UserInfo
                           on i.uAccount equals u.Account
                           where i.artNo == id
                           select new ArtHelper
                {
                    ID = i.ID,
                    Title = i.Title,
                    artNo = i.artNo,
                    artCreateTime = i.artCreateTime,
                    NickName = u.NickName,
                    uAccount = i.uAccount,
                    artContent = i.artContent,
                    artHot = i.artHot,
                    artComCnt = i.artComCnt,
                }
                           ).FirstOrDefault();

                ViewBag.NickName      = art.NickName;
                ViewBag.uAccount      = art.uAccount;
                ViewBag.Title         = art.Title;
                ViewBag.artContent    = art.artContent;
                ViewBag.artHot        = art.artHot;
                ViewBag.artComCnt     = art.artComCnt;
                ViewBag.artCreateTime = art.artCreateTime;
            }

            return(View());
        }
Exemple #7
0
        public ActionResult AddArt(ArticleInfo ai, int artClsTitle, int artAuthority, string artDigest)
        {
            string account = Server.HtmlEncode(Request.Cookies["Accout"].Value);

            string aiID = DateTime.Now.ToString("yyyyMMddHHmmss");

            ai.artNo         = aiID;
            ai.uAccount      = account;
            ai.artCreateTime = DateTime.Now;
            ai.artHot        = 0;
            ai.artClsID      = artClsTitle;
            ai.artAuthority  = artAuthority;
            ai.artComCnt     = 0;
            ai.artDigest     = artDigest.Trim();

            db.ArticleInfo.Add(ai);
            db.SaveChanges();

            return(RedirectToAction("SelectArt", "home", new { id = aiID }));
        }
 public ActionResult UserManageDel(List <int?> ID)
 {
     foreach (var i in ID)
     {
         UserInfo ui = db.UserInfo.Where(u => u.ID == i).FirstOrDefault();
         db.UserInfo.Remove(ui);
     }
     db.SaveChanges();
     return(Content("OK"));
 }
        //添加关注作者
        public ActionResult Add(string attenUser)
        {
            try
            {
                using (StoryBlog_DBEntities db = new StoryBlog_DBEntities())
                {
                    string account = Server.HtmlEncode(Request.Cookies["Accout"].Value);

                    //检测数据库是否有改数据,没有则添加
                    var at = db.AttentionInfo.Where(a => a.attenUser == attenUser).FirstOrDefault();

                    if (at == null)
                    {
                        AttentionInfo atten = new AttentionInfo();
                        atten.attenUser = attenUser;
                        atten.uAccount  = account;
                        db.AttentionInfo.Add(atten);
                        db.SaveChanges();

                        var obj = new
                        {
                            ok = "true"
                        };

                        return(Json(obj, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var obj = new
                        {
                            no = "true"
                        };

                        return(Json(obj, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception)
            {
                var obj = new
                {
                    dl = "true"
                };

                return(Json(obj, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Index(UserInfo userinfo, string NickName, string Account, string PassWord, string PassWord1, string name)
        {
            //判断验证码
            if (name != Session["ValidateNum"].ToString())
            {
                return(Content("<script>alert('验证码错误请注意大小写,请重新输入!');history.go(-1);</script>"));
            }
            else
            {
                userinfo.NickName   = NickName;
                userinfo.Account    = Account;
                userinfo.PassWord   = PassWord;
                userinfo.Gender     = "保密";
                userinfo.Describe   = "这个人很懒,什么都没有...";
                userinfo.Introduce  = "这个人很懒,什么都没有...";
                userinfo.CreateTime = DateTime.Now;
                db.UserInfo.Add(userinfo);

                //创建默认的日志
                ArticleClass ac = new ArticleClass();
                ac.artClsTitle = "默认日志";
                ac.uAccount    = Account;
                db.ArticleClass.Add(ac);

                //创建默认的相册
                PictureClass pc = new PictureClass();
                //pc.CoverFile = "/UploadPicture/ImagesFile/20170921061035749421.jpg";
                pc.picClsTitle      = "默认相册";
                pc.uAccount         = Account;
                pc.picClsAuthority  = 0;
                pc.picClsDescribe   = "这是系统创建默认的相册。";
                pc.picClsPicCnt     = 0;
                pc.picClsCreateTime = DateTime.Now;
                db.PictureClass.Add(pc);

                db.SaveChanges();
                return(RedirectToAction("Index", "login"));
            }
        }
        public ActionResult UploadPic(HttpPostedFileBase file)
        {
            string account = Server.HtmlEncode(Request.Cookies["Accout"].Value);

            if (file != null)
            {
                FileInfo fi = new FileInfo(file.FileName);
                string   hz = fi.Extension;

                string time = DateTime.Now.ToString("yyyyMMddHHmmssffffff");

                if (file.ContentLength > 0 && hz == ".jpg" || hz == ".gif" || hz == ".png")
                {
                    file.SaveAs(Server.MapPath("~/UploadPicture/HeadPicture/" + time + hz));
                    using (StoryBlog_DBEntities db = new StoryBlog_DBEntities())
                    {
                        var user = db.UserInfo.Where(u => u.Account == account).FirstOrDefault();
                        user.Picture = "/UploadPicture/HeadPicture/" + time + hz;
                        db.SaveChanges();
                    }
                    Select1();
                    Session["pic"] = null;
                    ViewBag.cg     = "上传成功!!!";
                }
                else
                {
                    ViewBag.cg1 = "SORRY!!!上传失败!!!请用.jpg/.gif/.png的照片上传。";
                    return(View());
                }
            }
            else
            {
                ViewBag.cg1 = "SORRY!!!未选择上传的文件!!!";
                return(View());
            }

            return(View());
        }
        public ActionResult Setting(string oldapwd, string apwd, string reapwd)
        {
            using (StoryBlog_DBEntities db = new StoryBlog_DBEntities())
            {
                var ad = db.Administration.Where(a => a.aAccount == account).FirstOrDefault();

                string PassWord = ad.aPwd;

                //判断密码是否为空
                if (oldapwd != "" && apwd != "" && reapwd != "")
                {
                    //判断原始密码是否正确
                    if (PassWord == oldapwd)
                    {
                        //判断是否包含英文字符
                        char[] ch = new char[apwd.Length];
                        ch = apwd.ToCharArray();
                        bool flag = false;
                        foreach (var item in ch)
                        {
                            if ((item >= 'a' && item < 'z') || (item >= 'A' && item < 'Z'))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                        {
                            //判断输入新密码的长度
                            if (apwd.Length >= 8 && apwd.Length <= 16)
                            {
                                //判断两次密码是否一致
                                if (apwd == reapwd)
                                {
                                    ad.aPwd = reapwd;

                                    db.SaveChanges();

                                    var obj = new
                                    {
                                        success = "true"
                                    };

                                    return(Json(obj, JsonRequestBehavior.AllowGet));
                                }
                                else
                                {
                                    return(Content("<script>alert('SORRY!!!两次密码输不一致!');</script>"));
                                }
                            }
                            else
                            {
                                return(Content("<script>alert('SORRY!!!请输入包含英文字母的8到16位的密码。');</script>"));
                            }
                        }

                        else
                        {
                            return(Content("<script>alert('SORRY!!!请输入包含英文字母的8到16位的密码。');</script>"));
                        }
                    }
                    else
                    {
                        return(Content("<script>alert('SORRY!!!原密码输入错误!');</script>"));
                    }
                }
                else
                {
                    return(Content("<script>alert('SORRY!!!密码不能为空,请输入密码!');</script>"));
                }
            }
        }
        public ActionResult UpdatePwd(string oldpwd, string pwd, string repwd)
        {
            string account = Server.HtmlEncode(Request.Cookies["Accout"].Value);

            using (StoryBlog_DBEntities db = new StoryBlog_DBEntities())
            {
                var    user     = db.UserInfo.Where(u => u.Account == account);
                string PassWord = user.FirstOrDefault().PassWord;

                //判断密码是否为空
                if (oldpwd != "" && pwd != "" && repwd != "")
                {
                    //判断原始密码是否正确
                    if (PassWord == oldpwd)
                    {
                        //判断是否包含英文字符
                        char[] ch = new char[pwd.Length];
                        ch = pwd.ToCharArray();
                        bool flag = false;
                        foreach (var item in ch)
                        {
                            if ((item >= 'a' && item < 'z') || (item >= 'A' && item < 'Z'))
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                        {
                            //判断输入新密码的长度
                            if (pwd.Length >= 6 && pwd.Length <= 12)
                            {
                                //判断两次密码是否一致
                                if (pwd == repwd)
                                {
                                    user.FirstOrDefault().PassWord = repwd;

                                    db.SaveChanges();

                                    ViewBag.Info1 = "密码修改成功!";
                                }
                                else
                                {
                                    ViewBag.Info2 = "SORRY!!!两次密码输不一致!";
                                }
                            }
                            else
                            {
                                ViewBag.Info2 = "SORRY!!!密码不符合输入的规格!请输入6到12位的英文字母或数字。";
                            }
                        }

                        else
                        {
                            ViewBag.Info2 = "SORRY!!!密码不符合输入的规格!请输入包含英文字母的6到12位的密码。";
                        }
                    }
                    else
                    {
                        ViewBag.Info2 = "SORRY!!!原密码输入错误!";
                    }
                }
                else
                {
                    ViewBag.Info2 = "SORRY!!!密码不能为空,请输入密码!";
                }
            }

            return(View());
        }