//Arun Geo Thomas public static JSData ReadJS() { JSData data = null; IntPtr aP = ReadJoystick(); int[] a = new int[6]; Marshal.Copy(aP, a, 0, 6); //array_release(aP); if (a[5] == 1) { JSData.VALIDREAD = true; data = new JSData(); JSData.ROLL = a[0] - 32767; JSData.PITCH = a[1] - 32767; JSData.YAW = a[2] - 32767; JSData.LIFT = a[3] - 32767; JSData.KILL = (a[4] == 1) ? true : false; } else { JSData.VALIDREAD = false; } return(data); }
/// <summary> /// 主要是通过post 且不需要返回值的时候 /// </summary> /// <returns></returns> public string GetActivate() { JSData jsdata = new JSData(); GetActivate(ref jsdata); return(jsdata.ToJson()); }
public JsonResult EmailValidation(string UserMail) { var email = UserMail; JsonResult jsonRe = new JsonResult(); JSData jsdata = new JSData(); if (null == Session[tempUserinfo]) { jsdata.State = EnumState.失败; jsdata.JSurl = "/UserManage/Login"; } else if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(email.Trim())) { jsdata.Messg = "邮箱不能为空~"; jsdata.State = EnumState.失败; } else if (BLL.Common.CacheData.GetAllUserInfo().Where(t => t.UserMail == email.Trim()).Count() >= 1) { jsdata.Messg = "此邮箱已被占用~"; jsdata.State = EnumState.失败; } else// if (null != Session[tempUserinfo]) { var userobj = (ModelDB.BlogUsersSet)Session[tempUserinfo]; userobj.UserMail = email;//z GetActivate(out jsdata); // return jsdata.ToJson(); } jsonRe.Data = jsdata; return(jsonRe); }
/// <summary> /// (无效邮箱)重新绑定邮箱 邮箱发送成功 默认跳转到激活页面 /// </summary> /// <param name="id"></param> /// <returns></returns> public JSData EmailValidation(string UserMail) { JSData jsdata = new JSData(); jsdata.State = EnumState.失败; if (null == Session[tempUserinfo]) { jsdata.JSurl = "/UserManage/Login"; } else if (string.IsNullOrEmpty(UserMail) || string.IsNullOrEmpty(UserMail.Trim())) { jsdata.Messg = "邮箱不能为空~"; } else if (GetDataHelper.GetAllUser().Where(t => t.UserMail == UserMail.Trim()).Count() >= 1) { jsdata.Messg = "此邮箱已被占用~"; } else { var userobj = (BlogUser)Session[tempUserinfo]; userobj.UserMail = UserMail; GetActivate(ref jsdata); } return(jsdata); }
public ActionResult Login(BlogUsers user, bool RememberMe) { JSData json = new JSData(); BLL.BlogUsersBLL userBLL = new BLL.BlogUsersBLL(); BlogUsers userResult = userBLL.GetList(t => t.UserName == user.UserName).FirstOrDefault(); if (userResult == null) //用户不存在 { json.Message = "用户不存在!"; } else if (userResult.UserPass == user.UserPass) //登录成功 { BLLSession.UserInfoSessioin = userResult; if (!string.IsNullOrEmpty(Request.QueryString["href"])) { json.JSurl = Request.QueryString["href"]; } else { json.JSurl = "/"; } if (RememberMe == true) { HttpCookie cookie = CookieHelper.GetCookie("userInfo"); if (cookie == null) { cookie = new HttpCookie("userInfo"); cookie.Values.Add("userName", user.UserName); cookie.Values.Add("userPass", user.UserPass); cookie.Expires = DateTime.Now.AddMonths(6); //setting the valid time of the cookie [6 months] CookieHelper.AddCookie(cookie); } else { if (!cookie.Values["userName"].Equals(user.UserName)) { CookieHelper.SetCookie("userInfo", "userName", user.UserName, DateTime.Now.AddMonths(6)); } if (!cookie.Values["userPass"].Equals(user.UserPass)) { CookieHelper.SetCookie("userInfo", "userPass", user.UserPass, DateTime.Now.AddMonths(6)); } } } else { CookieHelper.RemoveCookie("userInfo"); } } else //密码错误,登录失败 { json.Message = "密码错误!"; } return(Json(json)); }
/// <summary> /// 新增文章类型 /// </summary> /// <param name="newtypename"></param> /// <param name="userid"></param> /// <returns></returns> public ActionResult NewAddType(string newtypename) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (string.IsNullOrEmpty(newtypename)) { jsdata.Messg = "类型不能为空~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(Json(jsdata)); } #endregion int userid = BLLSession.UserInfoSessioin.Id; var user = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == userid, isAsNoTracking: false).FirstOrDefault(); BLL.BaseBLL <BlogType> bll = new BaseBLL <BlogType>(); bll.Insert( new BlogType() { TypeName = newtypename, BlogUser = user, IsDelte = false } ); if (bll.save() > 0)//保存 { //BLL.Common.CacheData.GetAllType(true);//更新缓存 jsdata.State = EnumState.成功; jsdata.Messg = "新增成功~"; } else { jsdata.State = EnumState.失败; jsdata.Messg = "新增失败~"; } return(Json(jsdata)); }
/// <summary> /// 获取激活码 (邮件发送成功 默认跳转到激活页面) /// </summary> /// <param name="username">用户名</param> /// <param name="mail">邮箱地址</param> /// <returns></returns> public bool GetActivate(out JSData jsdata) { var json = new Common.CustomModel.JSData(); #region 1.验证是否正常途径访问获取激活码 方法 if (null == Session[tempUserinfo]) { json.State = EnumState.失败; //json.Messg = "请您通过正常途径访问激活页面~"; json.JSurl = "/"; jsdata = json; return(false); } #endregion Session[jihuoma] = new Random().Next(999999999).ToString(); #region 2.发送邮件 如果邮件发送成功 默认跳转到 激活页面 Helper.EmailHelper email = new Helper.EmailHelper() { mailPwd = s_mailPwd, host = s_host, mailFrom = s_mailFrom, mailSubject = "[嗨-博客]激活码", mailBody = "欢迎激活 “嗨-博客”</br></br>您注册的的帐号:" + ((ModelDB.BlogUsersSet)Session[tempUserinfo]).UserName + " 激活码:" + Session[jihuoma].ToString(), mailToArray = new string[] { ((ModelDB.BlogUsersSet)Session[tempUserinfo]).UserMail } }; try { email.Send(); json.State = EnumState.正常重定向; json.Messg = "激活码已经发送邮箱~请注意查收~"; json.JSurl = "/UserManage/Activate"; jsdata = json; return(true); } catch (Exception ex) { json.State = EnumState.失败; json.Messg = ex.Message; jsdata = json; return(false); } #endregion }
/// <summary> /// 新增文章类型 /// </summary> /// <param name="newtypename"></param> /// <param name="userid"></param> /// <returns></returns> public ActionResult NewAddType(string newtypename) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (string.IsNullOrEmpty(newtypename)) { jsdata.Messg = "类型不能为空~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(Json(jsdata)); } #endregion int userid = BLLSession.UserInfoSessioin.Id; BLL.BlogTypesBLL bll = new BlogTypesBLL(); bll.Add( new ModelDB.BlogTypes() { TypeName = newtypename, UsersId = userid, IsDel = false } ); if (bll.save() > 0) //保存 { BLL.Common.CacheData.GetAllType(true); //更新缓存 jsdata.State = EnumState.成功; jsdata.Messg = "新增成功~"; } else { jsdata.State = EnumState.失败; jsdata.Messg = "新增失败~"; } return(Json(jsdata)); }
/// <summary> /// 编辑文章类型 /// </summary> /// <param name="typename"></param> /// <param name="typeid"></param> /// <returns></returns> public ActionResult EditType(string typename, int typeid) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (string.IsNullOrEmpty(typename)) { jsdata.Messg = "类型不能为空~"; } else if (null == typeid) { jsdata.Messg = "未取到文章ID~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(Json(jsdata)); } #endregion BLL.BlogTypesBLL bll = new BlogTypesBLL(); var blogtype = new ModelDB.BlogTypes() { Id = typeid, TypeName = typename }; bll.Up(blogtype, "TypeName"); if (bll.save() > 0) //保存 { BLL.Common.CacheData.GetAllType(true); //更新缓存 jsdata.State = EnumState.成功; // jsdata.Messg = "修改成功~"; } else { jsdata.State = EnumState.失败; jsdata.Messg = "操作失败~"; } return(Json(jsdata)); }
public ActionResult Register(BlogUsers user) { JSData json = new JSData(); BlogTypesBLL typeBLL = new BlogTypesBLL(); BlogUsersBLL userBLL = new BlogUsersBLL(); BlogUsers checkName = userBLL.GetList(t => t.UserName == user.UserName).FirstOrDefault(); BlogUsers checkEmail = userBLL.GetList(t => t.Email == user.Email).FirstOrDefault(); if (checkName != null) { json.State = EnumState.失败; json.Message = "用户名已存在!"; } else if (checkEmail != null) { json.State = EnumState.失败; json.Message = "该邮箱已被注册!"; } else { user.UserNickname = user.UserName; userBLL.Add(user); typeBLL.Add(new BlogTypes { TypeName = "未分类", UserId = user.UserId, BlogUsers = user }); try { userBLL.save(); typeBLL.save(); }catch (Exception ex) { throw ex; } BLL.DataCache.GetUsersInfo(true);//更新缓存 BLLSession.UserInfoSessioin = user; json.State = EnumState.正常重定向; json.JSurl = "/"; json.Message = "恭喜你," + user.UserName + "注册成功!"; } return(Json(json)); }
/// <summary> /// 重置密码 /// </summary> /// <returns></returns> public JSData ResetPass(BlogUser blog) { var pass = blog.UserPass; var email = blog.UserMail; var objJson = new JSData(); #region 1.数据验证 if (string.IsNullOrEmpty(pass.Trim())) { objJson.Messg = "新密码不能为空~"; } if (string.IsNullOrEmpty(email.Trim())) { objJson.Messg = "邮箱不能为空~"; } if (!string.IsNullOrEmpty(objJson.Messg)) { objJson.State = EnumState.失败; return(objJson); } #endregion var obj = GetDataHelper.GetAllUser().Where(t => t.UserMail == email); if (null == obj || obj.Count() <= 0) { objJson.State = EnumState.失败; objJson.Messg = "您输入的邮箱不是注册时候的邮箱~"; } else { Session[tempUserinfo] = obj.FirstOrDefault(); var userobj = (BlogUser)Session[tempUserinfo]; userobj.UserPass = pass;//z GetActivate(ref objJson); } return(objJson); }
public JsonResult Regis(BlogUsersSet blog) { JsonResult jsonresult = new JsonResult(); var json = new Common.CustomModel.JSData(); #region 1.数据检验 if (CacheData.GetAllUserInfo(true).Where(t => t.UserMail == blog.UserMail).Count() > 0) { json.Messg = "此邮箱已经被注册~换个邮箱吧~"; } else if (CacheData.GetAllUserInfo().Where(t => t.UserName == blog.UserName).Count() > 0) { json.Messg = "此用户名已经存在~"; } if (!string.IsNullOrEmpty(json.Messg)) { json.State = EnumState.失败; jsonresult.Data = json; return(jsonresult); } #endregion Blogs.ModelDB.BlogUsersSet user = new ModelDB.BlogUsersSet() { UserName = blog.UserName, UserPass = blog.UserPass, UserMail = blog.UserMail, UserNickname = blog.UserNickname, IsLock = true, UserInfo = new UserInfo() }; Session[tempUserinfo] = user; JSData jsdata; #region 2.邮件发送失败 if (!GetActivate(out jsdata)) // { jsdata.State = EnumState.失败; jsdata.Messg = jsdata.Messg + " ~请重新输入邮箱~"; } #endregion #region 3.邮件发送成功 else { BLL.BlogUsersSetBLL userBll = new BLL.BlogUsersSetBLL(); userBll.Add(user); //在保存前 再做次验证 if (GetDataHelper.GetAllUser().Where(t => t.UserName == blog.UserName || t.UserMail == blog.UserMail).Count() > 0) { json.Messg = "此用户名后邮箱已经存在~"; json.State = EnumState.失败; jsonresult.Data = json; return(jsonresult); } else { userBll.save(); } //验证是否注册成功 (并重新加载缓存信息) if (CacheData.GetAllUserInfo(true).Where(t => t.UserName == blog.UserName && t.UserPass == blog.UserPass).Count() > 0) { BLLSession.UserInfoSessioin = user; } else { json = new JSData() { Messg = "注册失败", State = EnumState.失败 }; jsonresult.Data = json; return(jsonresult); } } #endregion jsonresult.Data = jsdata; return(jsonresult); }
public string Release() { JSData jsdata = new JSData(); var content = Request.Form["content"]; //正文内容 var title = Request.Form["title"]; //标题 var oldtag = Request.Form["oldtag"]; //旧的标签(从checkbox中选取的) var newtag = Request.Form["newtag"]; //新的标签(在tag_text中输入的) var type = Request.Form["chk_type"]; //文章类型 var isshowhome = Request.Form["isshowhome"]; //是否显示在主页 var blogid = Request.Form["blogid"]; // int numblogid = -1; int.TryParse(blogid, out numblogid); #region 数据验证 if (null == BLL.Common.BLLSession.UserInfoSessioin) { jsdata.Message = "您还未登录~"; } /*else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock) * jsdata.Message = "您的账户未激活,暂只能评论。~";*/ else if (string.IsNullOrEmpty(content)) { jsdata.Message = "内容不能为空~"; } else if (content.Length >= 300000) { jsdata.Message = "发布内容过多~"; } else if (string.IsNullOrEmpty(title)) { jsdata.Message = "标题不能为空~"; } else if (title.Length >= 100) { jsdata.Message = "标题过长~"; } if (!string.IsNullOrEmpty(jsdata.Message)) { jsdata.State = EnumState.失败; return(jsdata.ToJson()); } #endregion BLL.BlogsBLL blogbll = new BLL.BlogsBLL(); var blogtemp = blogbll.GetList(t => t.BlogId == numblogid, isAsNoTracking: false).FirstOrDefault(); var userid = numblogid > 0 ? blogtemp.UserId : BLLSession.UserInfoSessioin.UserId;//如果numblogid大于〇证明 是编辑修改 var sessionuserid = BLLSession.UserInfoSessioin.UserId; //获取得 文章 类型 BlogTypes myBlogType; if (type == null) { myBlogType = new BlogTypesBLL().GetList(t => (t.TypeName == "未分类" && t.UserId == BLLSession.UserInfoSessioin.UserId), isAsNoTracking: false).FirstOrDefault(); } else { var blogtype = int.Parse(type); myBlogType = new BLL.BlogTypesBLL().GetList(t => t.BlogTypeId == blogtype, isAsNoTracking: false).ToList().FirstOrDefault(); } //获取得 文章 tag标签集合 对象 //old var oldtaglist = oldtag.Split(',').ToList(); var myOldTag = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && oldtaglist.Contains(t.BlogTagName), isAsNoTracking: false).ToList(); //new var newtaglistname = newtag.Split(',').ToList(); //保存newtags到数据库 BlogTagsBLL tagBLL = new BlogTagsBLL(); List <string> distinctTemp = new List <string>(); foreach (string tagName in newtaglistname) { if (String.IsNullOrEmpty(tagName.Trim())) { continue; } if (distinctTemp.Contains(tagName.Trim())) { continue; } tagBLL.Add(new BlogTags { BlogTagName = tagName.Trim(), UserId = userid }); try { tagBLL.save(); } catch (Exception ex) { jsdata.Message = ex.ToString(); jsdata.State = EnumState.失败; return(jsdata.ToJson()); } distinctTemp.Add(tagName.Trim()); BLL.DataCache.GetAllTag(true); } ////////////////////// var myTags = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && newtaglistname.Contains(t.BlogTagName), isAsNoTracking: false).ToList(); myOldTag.ForEach(t => myTags.Add(t)); //ModelDB.Blogs blogtemp = new ModelDB.Blogs(); if (numblogid > 0) //如果有 blogid 则修改 { //blog = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault(); if (sessionuserid == blogtemp.UserId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户 { blogtemp.Content = content; blogtemp.BlogRemarks = MyHtmlHelper.GetHtmlText(content); blogtemp.Title = title; blogtemp.IsShowHome = isshowhome == "true"; blogtemp.BlogTypes = myBlogType; blogtemp.BlogTags.Clear();//更新之前要清空 否则会存在主外键约束异常 blogtemp.BlogTags = myTags; blogtemp.IsDel = false; blogtemp.IsForwarding = false; jsdata.Message = "修改成功~"; } else { jsdata.Message = "您没有编辑此博文的权限~"; jsdata.JSurl = "/"; jsdata.State = EnumState.失败; return(jsdata.ToJson()); } } else //否则是新发布 { var blogfirst = blogbll.GetList(t => t.UserId == sessionuserid).OrderByDescending(t => t.BlogId).FirstOrDefault(); //var blogtitle = blogtemp.BlogTitle; //if (blogfirst != null) // blogtitle = blogtemp.BlogTitle; if (null != blogfirst && blogfirst.Title == title) { jsdata.Message = "不能同时发表两篇一样标题的文章~"; } else { blogtemp = new Blogs() { UserId = sessionuserid, Content = content, BlogRemarks = MyHtmlHelper.GetHtmlText(content), Title = title, IsShowHome = isshowhome == "true", BlogTypes = myBlogType, BlogTags = myTags, IsDel = false, IsForwarding = false }; blogbll.Add(blogtemp); jsdata.Message = "发布成功~"; } } // try { if (blogbll.save(false) > 0) { blogtemp.BlogUrl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html"; blogbll.save(); BLL.DataCache.GetAllType(true); #region 添加 或 修改搜索索引 var newtagList = string.Empty; blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.BlogTagName + " "); var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html"; // SearchResult search = new SearchResult() // { // flag = blogtemp.UsersId, // id = blogtemp.Id, // title = blogtemp.BlogTitle, // clickQuantity = 0, // blogTag = newtagList, // content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.BlogContent), // url = newblogurl // }; // SafetyWriteHelper<SearchResult>.logWrite(search, PanGuLuceneHelper.instance.CreateIndex); // #endregion jsdata.State = EnumState.成功; jsdata.JSurl = "/" + DataCache.GetUsersInfo().Where(t => t.UserId == blogtemp.UserId).First().UserName + "/" + blogtemp.BlogId + ".html"; return(jsdata.ToJson()); } } catch (Exception ex) { jsdata.State = EnumState.失败; jsdata.Message = ex.ToString(); return(jsdata.ToJson()); } jsdata.State = EnumState.失败; return(jsdata.ToJson()); }
/// <summary> /// 注册 /// </summary> /// <returns></returns> public JSData Regis(BlogUser blog) { var json = new JSData(); #region 1.数据检验 if (GetDataHelper.GetAllUser().Where(t => t.UserMail == blog.UserMail).Count() > 0) { json.Messg = "此邮箱已经被注册~换个邮箱吧~"; } else if (GetDataHelper.GetAllUser().Where(t => t.UserName == blog.UserName).Count() > 0) { json.Messg = "此用户名已经存在~"; } if (!string.IsNullOrEmpty(json.Messg)) { json.State = EnumState.失败; return(json); } #endregion BlogUser user = new BlogUser() { UserName = blog.UserName, UserPass = blog.UserPass, UserMail = blog.UserMail, UserNickname = blog.UserNickname, IsLock = true, BlogUserInfo = new BlogUserInfo() }; HttpContext.Current.Session[tempUserinfo] = user; JSData jsdata = new JSData(); #region 2.邮件发送失败 if (!GetActivate(ref jsdata)) // { jsdata.State = EnumState.失败; jsdata.Messg = jsdata.Messg + " ~请重新输入邮箱~"; } #endregion #region 3.邮件发送成功 else { BLL.BaseBLL <BlogUser> userBll = new BLL.BaseBLL <BlogUser>(); userBll.Insert(user); //在保存前 再做次验证 if (GetDataHelper.GetAllUser().Where(t => t.UserName == blog.UserName || t.UserMail == blog.UserMail).Count() > 0) { json.Messg = "此用户名后邮箱已经存在~"; json.State = EnumState.失败; return(json); } else { userBll.save(); } //验证是否注册成功 (并重新加载缓存信息) if (GetDataHelper.GetAllUser().Where(t => t.UserName == blog.UserName && t.UserPass == blog.UserPass).Count() > 0) { BLLSession.UserInfoSessioin = user; json.JSurl = "/UserManage/Activate"; json.Messg = "请查收邮件,完成账号激活~"; } else { json.Messg = "注册失败"; json.State = EnumState.失败; return(json); } } #endregion return(json); }
/// <summary> /// 提交内容的编辑或修改 /// </summary> /// <param name="input"></param> /// <returns></returns> public JSData ReleasePost(ReleaseInput input) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLL.Common.BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock) { jsdata.Messg = "您的账户未激活,暂只能评论。~"; } else if (string.IsNullOrEmpty(input.Content)) { jsdata.Messg = "内容不能为空~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(jsdata); } #endregion BLL.BaseBLL <BlogInfo> blogbll = new BaseBLL <BlogInfo>(); var blogtemp = blogbll.GetList(t => t.Id == input.Blogid, isAsNoTracking: false).FirstOrDefault(); var userid = input.Blogid > 0 ? blogtemp.User.Id : BLLSession.UserInfoSessioin.Id;//如果numblogid大于〇证明 是编辑修改 var sessionuserid = BLLSession.UserInfoSessioin.Id; //获取得 文章 类型集合 对象 var typelist = new List <int>(); if (!string.IsNullOrEmpty(input.Chk_type)) { foreach (string type in input.Chk_type.Split(',').ToList()) { if (!string.IsNullOrEmpty(type)) { typelist.Add(int.Parse(type)); } } } // types.Split(',').ToList().ForEach(t => typelist.Add(int.Parse(t))); var myBlogTypes = new BLL.BaseBLL <BlogType>().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList(); //获取得 文章 tag标签集合 对象 //old var oldtaglist = string.IsNullOrEmpty(input.Oldtag) ? new List <string>() : input.Oldtag.Split(',').ToList(); var myOldTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList(); //new var newtaglist = input.Newtag.GetValueOrEmpty().Split(',').ToList(); AddTag(newtaglist, userid);//保存到数据库 var myNweTagTypes = new BLL.BaseBLL <BlogTag>().GetList(t => t.BlogUser.Id == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList(); myNweTagTypes.ForEach(t => myOldTagTypes.Add(t)); if (input.Blogid > 0) //如果有 blogid 则修改 { if (sessionuserid == blogtemp.User.Id || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户 { blogtemp.Content = input.Content; blogtemp.Title = input.Title; blogtemp.IsShowMyHome = input.Isshowmyhome; blogtemp.IsShowHome = input.Isshowhome; blogtemp.Types.Clear();//更新之前要清空 不如会存在主外键约束异常 blogtemp.Types = myBlogTypes; blogtemp.Tags.Clear(); blogtemp.Tags = myOldTagTypes; blogtemp.IsDelte = false; blogtemp.IsForwarding = false; jsdata.Messg = "修改成功~"; } else { jsdata.Messg = "您没有编辑此博文的权限~"; jsdata.JSurl = "/"; jsdata.State = EnumState.失败; return(jsdata); } } else //否则 新增 { var blogfirst = blogbll.GetList(t => t.User.Id == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault(); if (null != blogfirst && blogfirst.Title == input.Title) { jsdata.Messg = "不能同时发表两篇一样标题的文章~"; } else { var bloguser = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == BLLSession.UserInfoSessioin.Id, isAsNoTracking: false).FirstOrDefault(); blogtemp = new BlogInfo() { User = bloguser, Content = input.Content, Title = input.Title, BlogUpTime = DateTime.Now, BlogCreateTime = DateTime.Now, IsShowMyHome = input.Isshowmyhome, IsShowHome = input.Isshowhome, Types = myBlogTypes, Tags = myOldTagTypes, IsDelte = false, IsForwarding = false }; blogbll.Insert(blogtemp); jsdata.Messg = "发布成功~"; } } // if (blogbll.save(false) > 0) { #region 添加 或 修改搜索索引 try { var newtagList = string.Empty; blogtemp.Tags.Where(t => true).ToList().ForEach(t => newtagList += t.TagName + " "); var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.Id + ".html"; SearchResult search = new SearchResult() { flag = blogtemp.User.Id, id = blogtemp.Id, title = blogtemp.Title, clickQuantity = 0, blogTag = newtagList, content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.Content), url = newblogurl }; SafetyWriteHelper <SearchResult> .logWrite(search, PanGuLuceneHelper.instance.CreateIndex); } catch (Exception) { } #endregion jsdata.State = EnumState.成功; jsdata.JSurl = "/" + GetDataHelper.GetAllUser().Where(t => t.Id == blogtemp.User.Id).First().UserName + "/" + blogtemp.Id + ".html"; return(jsdata); } jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg; jsdata.State = EnumState.失败; return(jsdata); }
/// <summary> /// 激活 (实际上是验证激活码后 修改用户信息:包括是否激活IsLock、邮箱地址、密码 ) /// </summary> /// <returns></returns> public string Activate() { var json = new JSData(); #region 1.判断是否从正常途径访问此页面 如果是的话 默认存在 Session[tempUserinfo] 2.如果是已经登录状态则直接无视 跳转 if (null == Session[tempUserinfo]) { json.State = EnumState.失败;//json.Messg = "请您通过正常途径访问激活页面~"; json.JSurl = "/"; return(json.ToJson()); } if (BLLSession.UserInfoSessioin != null && !BLLSession.UserInfoSessioin.IsLock) { json.State = EnumState.失败; //json.Messg = "您都已经登录的还想获取激活码?别玩了~"; json.JSurl = "/"; return(json.ToJson()); } #endregion var tempuser = ((BlogUser)HttpContext.Current.Session[tempUserinfo]); var activate = HttpContext.Current.Request.Form["txt_activate"];//激活码 #region 2.验证激活码 (更新缓存 发送通知邮件 清空无用session) if (activate.Trim() == Session[jihuoma].ToString().Trim()) //验证激活码 { BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>(); var objuser = user.GetList(t => t.Id == tempuser.Id, isAsNoTracking: false).FirstOrDefault(); var isEffectiveEmail = !string.IsNullOrEmpty(objuser.UserMail) && objuser.UserMail != "无效";//是否是有效邮箱(迁移用户是无效邮箱) if (null != objuser) { objuser.IsLock = false; objuser.UserPass = isEffectiveEmail ? tempuser.UserPass.MD5().MD5() : defaulPass.MD5().MD5(); objuser.UserMail = tempuser.UserMail; if (objuser.BlogUserInfo == null) { objuser.BlogUserInfo = new BlogUserInfo() { BlogUpNum = 0 }; } } user.save(); #region bug 记录 //BlogUsers objuser = new BlogUsers(); //objuser.Id = id; //objuser.IsLock = false; // user.Up(objuser, "IsLock"); //这个方法 正常情况用没问题,如果先添加 然后修改就有问题 (不能用) #endregion bool islock = GetDataHelper.GetAllUser().Where(t => t.Id == tempuser.Id).FirstOrDefault().IsLock; if (!islock) { #region 发送邮件 告知 激活成功 var tempSessionUser = (BlogUser)Session[tempUserinfo]; var nickName = string.IsNullOrEmpty(tempSessionUser.UserNickname) ? tempSessionUser.UserName : tempSessionUser.UserName; Helper.EmailHelper email = new Helper.EmailHelper() { mailPwd = s_mailPwd, host = s_host, mailFrom = s_mailFrom, mailSubject = "欢迎您注册 嗨-博客", mailBody = EmailHelper.tempBody(nickName, "欢迎注册 嗨-博客", "您注册的的帐号:" + objuser.UserName + " 密码是:" + (isEffectiveEmail ? tempuser.UserPass : defaulPass), "请您妥善保管~"), mailToArray = new string[] { tempSessionUser.UserMail } }; try { email.Send(t => { LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送成功的邮件"); }, t => { LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送失败的邮件"); } ); } catch (Exception) { } #endregion Session[jihuoma] = null; Session[tempUserinfo] = null; BLLSession.UserInfoSessioin = objuser; return(new JSData() { Messg = "恭喜您~激活成功~", State = EnumState.正常重定向, JSurl = "/" }.ToJson()); } else { return(new JSData() { Messg = "激活失败,请联系管理员~", State = EnumState.失败 }.ToJson()); } } #endregion return(new JSData() { Messg = "您输入的激活码错误,你可以重新激活~", State = EnumState.失败 }.ToJson()); }
/// <summary> /// 获取激活码 (邮件发送成功 默认跳转到激活页面) /// </summary> /// <param name="username">用户名</param> /// <param name="mail">邮箱地址</param> /// <returns></returns> public bool GetActivate(ref JSData jsdata) { //验证是否正常途径访问获取激活码 方法 if (null == Session[tempUserinfo]) { jsdata.State = EnumState.失败; //json.Messg = "请您通过正常途径访问激活页面~"; jsdata.JSurl = "/"; return(false); } #region 频繁获取验证处理 if (Session["GetActivateTime"] == null) { Session["GetActivateTime"] = DateTime.Now; } if (Convert.ToDateTime(Session["GetActivateTime"]) > DateTime.Now) { jsdata.State = EnumState.失败; jsdata.Messg = "您获取激活码太过频繁,请15秒后再尝试。"; LogSave.WarnLogSave("IP:" + RequestHelper.GetIp() + "\r\n获取激活码频繁", "获取激活码频繁"); return(false); } Session["GetActivateTime"] = DateTime.Now.AddSeconds(15);//设置时间 #endregion //session记录激活码 Session[jihuoma] = new Random().Next(999999999).ToString(); #region 发送邮件 如果邮件发送成功 默认跳转到 激活页面 var tempSessionUser = (BlogUser)Session[tempUserinfo]; var nickName = string.IsNullOrEmpty(tempSessionUser.UserNickname) ? tempSessionUser.UserName : tempSessionUser.UserName; Helper.EmailHelper email = new Helper.EmailHelper() { mailPwd = s_mailPwd, host = s_host, mailFrom = s_mailFrom, mailSubject = "[嗨-博客]激活码", mailBody = EmailHelper.tempBody(nickName, " 激活码:" + Session[jihuoma].ToString()), mailToArray = new string[] { tempSessionUser.UserMail } }; try { email.Send(t => { LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送成功的邮件"); }, t => { LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送失败的邮件"); } ); jsdata.State = EnumState.正常重定向; jsdata.Messg = "激活码已经发送邮箱~请注意查收~"; jsdata.JSurl = "/UserManage/Activate"; return(true); } catch (Exception ex) { jsdata.State = EnumState.失败; jsdata.Messg = ex.Message; return(false); } #endregion }
public JsonResult Login(BlogUsersSet user, string ischeck) { JSData objJson = new JSData(); //var listUser = CacheData.GetAllUserInfo().Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == user.UserPass.MD5().MD5()); var pass = user.UserPass.MD5().MD5(); var listUser = GetDataHelper.GetAllUser(t => t.UserInfo).Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == pass); if (listUser.Count() > 0) { Session[tempUserinfo] = listUser.FirstOrDefault(); #region 1.验证邮箱是否有效 无效则跳转到邮箱验证页面 if (listUser.Where(t => t.UserMail == "无效" || string.IsNullOrEmpty(t.UserMail)).Count() > 0) { objJson.State = EnumState.失败; objJson.Messg = "检测到你注册的邮箱无效~请输入正确的邮箱~"; objJson.JSurl = "/UserManage/EmailValidation"; } #endregion #region 2.用户是否是激活状态 否:发送激活码 并跳转到激活页面 else if (listUser.Where(t => t.IsLock == true).Count() > 0) { //邮件发送激活码 //JSData jsdata; GetActivate(out objJson); //return Json(jsdata); } #endregion #region 3.登录成功 else { // var objuser = GetDataHelper.GetAllUser(t => t.UserInfo).Where(t => t.UserName == lodname.Trim() && t.UserPass == lodpass.Trim().MD5().MD5() && t.IsLock == false).FirstOrDefault(); BLLSession.UserInfoSessioin = listUser.FirstOrDefault(); //Messg = "登录成功", //不给提示 直接跳转 objJson.State = EnumState.正常重定向; if (!string.IsNullOrEmpty(Request.QueryString["href"])) { objJson.JSurl = Request.QueryString["href"]; } else { objJson.JSurl = "/"; } if (ischeck == "on") { //Helper.CookiesHelper.AddCookie("hib_name", user.UserName); //Helper.CookiesHelper.AddCookie("hib_pass", user.UserPass); HttpCookie Cookie = CookiesHelper.GetCookie("userInfo"); if (Cookie == null) { Cookie = new HttpCookie("userInfo"); Cookie.Values.Add("userName", user.UserName); Cookie.Values.Add("userPass", user.UserPass); //设置Cookie过期时间 Cookie.Expires = DateTime.Now.AddDays(365); CookiesHelper.AddCookie(Cookie); } else { if (!Cookie.Values["userName"].Equals(user.UserName)) { CookiesHelper.SetCookie("userInfo", "userName", user.UserName); } if (!Cookie.Values["userPass"].Equals(user.UserPass)) { CookiesHelper.SetCookie("userInfo", "userPass", user.UserPass); } } } else { Helper.CookiesHelper.RemoveCookie("userInfo"); } } #endregion } else { objJson.Messg = "用户名或密码错误~"; objJson.State = EnumState.失败; } return(Json(objJson)); //json; }
public JsonResult EmailValidation(string UserMail) { JSData jsdata = _userManageApplication.EmailValidation(UserMail); return(Json(jsdata)); }
public JSData Login(BlogUser user, string ischeck) { JSData objJson = new JSData(); var pass = user.UserPass.MD5().MD5(); var listUser = GetDataHelper.GetAllUser(t => t.BlogUserInfo).Where(t => (t.UserName == user.UserName || t.UserMail == user.UserName) && t.UserPass == pass); if (listUser.Count() > 0) { HttpContext.Current.Session[tempUserinfo] = listUser.FirstOrDefault(); //验证邮箱是否有效 无效则跳转到邮箱验证页面 if (listUser.Where(t => t.UserMail == "无效" || string.IsNullOrEmpty(t.UserMail)).Count() > 0) { objJson.State = EnumState.失败; objJson.Messg = "检测到你注册的邮箱无效~请输入正确的邮箱~"; objJson.JSurl = "/UserManage/EmailValidation"; } else if (listUser.Where(t => t.IsLock == true).Count() > 0)//用户是否是激活状态 否:发送激活码 并跳转到激活页面 { GetActivate(ref objJson); } else//登录成功 { #region 登录成功 BLLSession.UserInfoSessioin = listUser.FirstOrDefault(); //Messg = "登录成功", //不给提示 直接跳转 objJson.State = EnumState.正常重定向; if (!string.IsNullOrEmpty(Request.QueryString["href"])) { objJson.JSurl = Request.QueryString["href"]; } else { objJson.JSurl = "/"; } if (ischeck == "on") { HttpCookie Cookie = CookiesHelper.GetCookie("userInfo"); if (Cookie == null) { Cookie = new HttpCookie("userInfo"); Cookie.Values.Add("userName", user.UserName); Cookie.Values.Add("userPass", user.UserPass); //设置Cookie过期时间 Cookie.Expires = DateTime.Now.AddDays(365); CookiesHelper.AddCookie(Cookie); } else { if (!Cookie.Values["userName"].Equals(user.UserName)) { CookiesHelper.SetCookie("userInfo", "userName", user.UserName); } if (!Cookie.Values["userPass"].Equals(user.UserPass)) { CookiesHelper.SetCookie("userInfo", "userPass", user.UserPass); } } } else { Helper.CookiesHelper.RemoveCookie("userInfo"); } #endregion } } else { objJson.Messg = "用户名或密码错误~"; objJson.State = EnumState.失败; } return(objJson); }
public string Release() { JSData jsdata = new JSData(); var content = Request.Form["content"]; //正文内容 var title = Request.Form["title"]; //标题 var oldtag = Request.Form["oldtag"]; //旧的标签 var newtag = Request.Form["newtag"]; //新的标签 var types = Request.Form["chk_type"]; //文章类型 var isshowhome = Request.Form["isshowhome"]; //是否显示在主页 var isshowmyhome = Request.Form["isshowmyhome"]; //是否显示在个人主页 var blogid = Request.Form["blogid"]; // int numblogid = -1; int.TryParse(blogid, out numblogid); #region 数据验证 if (null == BLL.Common.BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock) { jsdata.Messg = "您的账户已经被锁定,请联系管理员~"; } else if (string.IsNullOrEmpty(content)) { jsdata.Messg = "内容不能为空~"; } else if (content.Length >= 80000) { jsdata.Messg = "发布内容过多~"; } else if (string.IsNullOrEmpty(title)) { jsdata.Messg = "标题不能为空~"; } else if (title.Length >= 100) { jsdata.Messg = "标题过长~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(jsdata.ToJson()); } #endregion BLL.BlogsBLL blogbll = new BLL.BlogsBLL(); var blogtemp = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault(); var userid = numblogid > 0 ? blogtemp.UsersId : BLLSession.UserInfoSessioin.Id;//如果numblogid大于〇证明 是编辑修改 var sessionuserid = BLLSession.UserInfoSessioin.Id; //获取得 文章 类型集合 对象 var typelist = new List <int>(); foreach (string type in types.Split(',').ToList()) { if (!string.IsNullOrEmpty(type)) { typelist.Add(int.Parse(type)); } } // types.Split(',').ToList().ForEach(t => typelist.Add(int.Parse(t))); var myBlogTypes = new BLL.BlogTypesBLL().GetList(t => typelist.Contains(t.Id), isAsNoTracking: false).ToList(); //获取得 文章 tag标签集合 对象 //old var oldtaglist = oldtag.Split(',').ToList(); var myOldTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && oldtaglist.Contains(t.TagName), isAsNoTracking: false).ToList(); //new var newtaglist = newtag.Split(',').ToList(); AddTag(newtaglist, userid);//保存到数据库 var myNweTagTypes = new BLL.BlogTagsBLL().GetList(t => t.UsersId == userid && newtaglist.Contains(t.TagName), isAsNoTracking: false).ToList(); myNweTagTypes.ForEach(t => myOldTagTypes.Add(t)); //ModelDB.Blogs blogtemp = new ModelDB.Blogs(); if (numblogid > 0) //如果有 blogid 则修改 { //blog = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault(); if (sessionuserid == blogtemp.UsersId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户 { blogtemp.BlogContent = content; blogtemp.BlogTitle = title; //blog.BlogUpTime = DateTime.Now; //blog.BlogCreateTime = DateTime.Now; blogtemp.IsShowMyHome = isshowmyhome == "true"; blogtemp.IsShowHome = isshowhome == "true"; blogtemp.BlogTypes.Clear();//更新之前要清空 不如会存在主外键约束异常 blogtemp.BlogTypes = myBlogTypes; blogtemp.BlogTags.Clear(); blogtemp.BlogTags = myOldTagTypes; blogtemp.IsDel = false; blogtemp.IsForwarding = false; jsdata.Messg = "修改成功~"; } else { jsdata.Messg = "您没有编辑此博文的权限~"; jsdata.JSurl = "/"; jsdata.State = EnumState.失败; return(jsdata.ToJson()); } } else //否则 新增 { var blogfirst = blogbll.GetList(t => t.UsersId == sessionuserid).OrderByDescending(t => t.Id).FirstOrDefault(); //var blogtitle = blogtemp.BlogTitle; //if (blogfirst != null) // blogtitle = blogtemp.BlogTitle; if (null != blogfirst && blogfirst.BlogTitle == title) { jsdata.Messg = "不能同时发表两篇一样标题的文章~"; } else { blogtemp = new ModelDB.Blogs() { UsersId = sessionuserid, BlogContent = content, BlogTitle = title, BlogUpTime = DateTime.Now, BlogCreateTime = DateTime.Now, IsShowMyHome = isshowmyhome == "true", IsShowHome = isshowhome == "true", BlogTypes = myBlogTypes, BlogTags = myOldTagTypes, IsDel = false, IsForwarding = false }; blogbll.Add(blogtemp); jsdata.Messg = "发布成功~"; } } // if (blogbll.save(false) > 0) { #region 添加 或 修改搜索索引 try { var newtagList = string.Empty; blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.TagName + " "); var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.Id + ".html"; SearchResult search = new SearchResult() { flag = blogtemp.UsersId, id = blogtemp.Id, title = blogtemp.BlogTitle, clickQuantity = 0, blogTag = newtagList, content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.BlogContent), url = newblogurl }; SafetyWriteHelper <SearchResult> .logWrite(search, PanGuLuceneHelper.instance.CreateIndex); } catch (Exception) { } #endregion jsdata.State = EnumState.成功; jsdata.JSurl = "/" + CacheData.GetAllUserInfo().Where(t => t.Id == blogtemp.UsersId).First().UserName + "/" + blogtemp.Id + ".html"; return(jsdata.ToJson()); } jsdata.Messg = string.IsNullOrEmpty(jsdata.Messg) ? "操作失败~" : jsdata.Messg; jsdata.State = EnumState.失败; return(jsdata.ToJson()); }
//获取激活码 public bool GetActivate(ref JSData jsdata) { return(_userManageApplication.GetActivate(ref jsdata)); }