/// <summary> /// 注册限制 /// </summary> /// <returns></returns> public static bool RegLimit() { bool b = true; List <dbParam> list = new List <dbParam>() { new dbParam() { ParamName = "@ClientIP", ParamValue = WebHelp.GetIP() }, }; #region 一IP,同一当前日期(年月日),可以确定当天注册次数。 List <User> uList = UserDal.m_UserDal.GetList(" ClientIP=@ClientIP", list); int count = 0; string DateCurrent = string.Format("{0:D}", DateTime.Now);//设置当前日期(年-月-日) foreach (var u in uList) { if (DateCurrent == string.Format("{0:D}", u.CreatedTime)) { count++; } } #endregion if (count >= 3) { b = false; } return(b); }
/// <summary> /// 添加图书评论的回复2 /// </summary> /// <returns></returns> public string AddBookCommentReplyAgain() { int BookRemarkReplyId = int.Parse(context.Request.Form["iBookRemarkReplyId"].ToString()); //对哪条回复的回复 BookRemarkReply ReplyTo = BookDetailsDAL.m_BookRemarkReplyDal.GetModel(BookRemarkReplyId); int UserId = ReplyTo.UserId; string UserName = "******" + ReplyTo.UserName; string sBookRemarksReplyAgain = context.Request.Form["sBookRemarksReplyAgain"].ToString(); rm.Success = true; try { BookRemarkReply bookRemarkReply = new BookRemarkReply(); bookRemarkReply.BookRemarkId = ReplyTo.BookRemarkId; bookRemarkReply.BookId = ReplyTo.BookId; bookRemarkReply.UserId = UserId; bookRemarkReply.BookRemarksReply = sBookRemarksReplyAgain; bookRemarkReply.UserName = UserName; bookRemarkReply.ClientIP = WebHelp.GetIP(); bookRemarkReply.CreatedTime = DateTime.Now; if (CRegex.FilterHTML(bookRemarkReply.BookRemarksReply) == "") { rm.Info = "内容不能为空"; return(jss.Serialize(rm)); } int iBookRemarkReplyId = BookDetailsDAL.m_BookRemarkReplyDal.Add(bookRemarkReply); } catch (Exception) { rm.Success = false; rm.Info = "未知错误"; } return(jss.Serialize(rm)); }
/// <summary> /// 添加图书评论 /// </summary> /// <returns></returns> public string AddBookComment() { int BookId = int.Parse(context.Request.Form["iBookId"].ToString()); User u = UserDal.CurrentUser(); int UserId = u.UserId; string UserName = u.UserName; string BookRemarks = context.Request.Form["sBookRemarks"].ToString(); rm.Success = true; try { BookRemark bookRemark = new BookRemark(); bookRemark.BookId = BookId; bookRemark.UserId = UserId; bookRemark.BookRemarks = BookRemarks; bookRemark.UserName = UserName; bookRemark.ClientIP = WebHelp.GetIP(); bookRemark.CreatedTime = DateTime.Now; if (CRegex.FilterHTML(bookRemark.BookRemarks) == "") { rm.Info = "内容不能为空"; return(jss.Serialize(rm)); } int iBookRemarkId = BookDetailsDAL.m_BookRemarkDal.Add(bookRemark); } catch (Exception) { rm.Success = false; rm.Info = "未知错误"; } return(jss.Serialize(rm)); }
/// <summary> /// 用户注册 /// </summary> /// <returns></returns> public string RegUser() { string username = context.Request.Form["username"].ToString(); string pwd = context.Request.Form["pwd"].ToString(); string email = context.Request.Form["email"].ToString(); string phonenum = context.Request.Form["phonenum"].ToString(); string qq = context.Request.Form["qq"].ToString(); string checkcode = context.Request.Form["checkcode"].ToString(); if (checkcode != context.Session["CheckCode"].ToString())//Session["CheckCode"] = rand;在image.aspx页面设置 { rm.Success = false; rm.Info = "验证码输入不正确"; } else { try { User user = new User(); user.UserName = username; user.Pwd = pwd; user.Gender = "男";//默认为男,可在个人中心更改 user.Email = email; user.Tel = phonenum; user.QQ = qq; user.Type = 0; //1管理员 0普通用户 user.ClientIP = WebHelp.GetIP(); //获取到访问者的IP user.CreatedTime = DateTime.Now; user.HeadPic = "man.GIF"; if (!UserDal.RegLimit()) { rm.Info = "sorry,一天最多只能注册三次"; } else { int userid = UserDal.m_UserDal.Add(user); //存储注册者的 ip/用户id/密码 并加密 cookieHelper.SetCookie("CLoginUser", cookieHelper.EncryptCookie(string.Format("{0}/{1}/{2}", WebHelp.GetIP(), userid, pwd)), 20); rm.Success = true; rm.Info = "恭喜您,注册成功,3秒后返回首页..."; } } catch { rm.Info = "未知错误"; } } return(jss.Serialize(rm)); }
public static bool RegLimit() { bool b = true; List <dbParam> list = new List <dbParam>() { new dbParam() { ParamName = "@ClientIP", ParamValue = WebHelp.GetIP() }, new dbParam() { ParamName = "@Time", ParamValue = DateTime.Now.ToString("yyyy-MM-dd") } }; int count = m_UserInforDAL.GetCount(" RegIP=@ClientIP and CONVERT(varchar(100), CreatedTime, 23)=@Time", list); if (count >= 3) { b = false; } return(b); }
/// <summary> /// 获取当前用户 /// </summary> /// <returns></returns> public static User CurrentUser() { User user = null; if (System.Web.HttpContext.Current.Request.Cookies["CLoginUser"] == null || System.Web.HttpContext.Current.Request.Cookies["CLoginUser"].Value == "") { return(user); } else { //获取当前用户的Cookies并解密 string strLoginUser = cookieHelper.DecryptCookie(System.Web.HttpContext.Current.Request.Cookies["CLoginUser"].Value); string[] aLoginUser = strLoginUser.Split('/'); if (aLoginUser.Length != 3) { user = null; } if (WebHelp.GetIP() != aLoginUser[0]) { user = null; } else { user = UserDal.m_UserDal.GetModel("UserId=@UserId", new List <dbParam>() { new dbParam() { ParamName = "@UserId", ParamValue = Convert.ToInt32(Convert.ToInt32(aLoginUser[1])) } }); if (user.Pwd != aLoginUser[2]) { user = null; } } } return(user); }
public static UserInfor CurrentUser() { UserInfor user = null; if (System.Web.HttpContext.Current.Request.Cookies["CLoginUser"] == null || System.Web.HttpContext.Current.Request.Cookies["CLoginUser"].Value == "") { return(user); } else { string strLoginUser = cookieHelper.DecryptCookie(System.Web.HttpContext.Current.Request.Cookies["CLoginUser"].Value); string[] aLoginUser = strLoginUser.Split('/'); if (aLoginUser.Length != 3) { user = null; } if (WebHelp.GetIP() != aLoginUser[0]) { user = null; } else { user = m_UserInforDAL.GetModel("Xuehao=@xuehao", new List <dbParam>() { new dbParam() { ParamName = "@xuehao", ParamValue = aLoginUser[1].ToString() } }); if (user.password != aLoginUser[2]) { user = null; } } } return(user); }
/// <summary> /// 用户登录 /// </summary> /// <returns></returns> public string UserLogin() { string username = context.Request.Form["username"].ToString(); string pwd = context.Request.Form["pwd"].ToString(); try { List <dbParam> list = new List <dbParam>() { new dbParam() { ParamName = "@UserName", ParamValue = username }, new dbParam() { ParamName = "@Pwd", ParamValue = pwd } }; User user = UserDal.m_UserDal.GetModel("UserName=@UserName and Pwd=@Pwd", list); //保存UserId,为后面的页面使用;比如购物车页面。 //HttpContext.Current.Session["UserId"] = user.UserId; cookieHelper.SetCookie("UserId", user.UserId.ToString(), 3600); if (user != null) { //存储登录者的 ip/用户id/密码 并加密 cookieHelper.SetCookie("CLoginUser", cookieHelper.EncryptCookie(string.Format("{0}/{1}/{2}", WebHelp.GetIP(), user.UserId, user.Pwd)), 60); rm.Success = true; } else { rm.Info = "用户名或密码错误"; } } catch { rm.Info = "未知错误"; } return(jss.Serialize(rm)); }
public string AddComment() { string title = context.Request.Form["title"].ToString(); string text = context.Request.Form["text"].ToString(); //过滤html标签再判断是否为空 if (CRegex.FilterHTML(text) == "") { rm.Info = "内容不能为空"; return(jss.Serialize(rm)); } else if (CRegex.FilterHTML(text).Length > 500 || CRegex.FilterHTML(text).Length < 6) { rm.Info = "问题内容长度在6~500之间"; return(jss.Serialize(rm)); } else { string strIP = WebHelp.GetIP(); User user = UserDal.CurrentUser();//获取当前登陆用户 List <dbParam> list = new List <dbParam>() { new dbParam() { ParamName = "@ClientIP", ParamValue = strIP }, new dbParam() { ParamName = "@UserId", ParamValue = user.UserId } }; #region 一IP,同一当前日期(年月日),可以确定当天评论次数。 List <WebComment> wList = WebCommentDAL.m_WebCommentDal.GetList(" ClientIP=@ClientIP and UserId=@UserId", list); int count = 0; if (wList.Count == 0) { count = 0; } else { string DateCurrent = string.Format("{0:D}", DateTime.Now);//设置当前日期(年-月-日) foreach (var w in wList) { if (DateCurrent == string.Format("{0:D}", w.CreatedTime)) { count++; } } } #endregion //同一用户不能一天超过三次留言 if (count >= 3) { rm.Info = "一天最多只能发帖三次"; jss.Serialize(rm); } else { if (user.Type < 0) { rm.Info = "只有已登录用户才能发帖"; jss.Serialize(rm); } else { WebComment webCom = new WebComment(); webCom.CommentTitle = title; webCom.CommentText = text; webCom.CreatedTime = DateTime.Now; webCom.ClientIP = WebHelp.GetIP(); webCom.UserId = user.UserId; WebCommentDAL.m_WebCommentDal.Add(webCom); rm.Success = true; rm.Info = "提交成功"; } } } return(jss.Serialize(rm)); }
public ReturnMessage Login(string a, string b) { try { UserInfor user = null; List <dbParam> list = new List <dbParam>() { new dbParam() { ParamName = "@xuehao", ParamValue = a }, new dbParam() { ParamName = "@pwd", ParamValue = b } }; user = UserInforDAL.m_UserInforDAL.GetModel("Xuehao=@xuehao and Password=@pwd", list); if (user != null) { cookieHelper.SetCookie("CLoginUser", cookieHelper.EncryptCookie(string.Format("{0}/{1}/{2}", WebHelp.GetIP(), user.Xuehao, user.password)), 60); rm.Success = true; rm.Info = user.Uavatar; } else { rm.Success = false; } return(rm); } catch (Exception em) { throw; } }
/// <summary> /// 回复当前用户的评论 /// </summary> /// <returns></returns> public string AddReplyComment() { int webCommentId = Convert.ToInt32(context.Request.Form["webCommentId"].ToString()); string text = context.Request.Form["text"].ToString(); if (CRegex.FilterHTML(text) == "") { rm.Info = "内容不能为空"; return(jss.Serialize(rm)); } else if (CRegex.FilterHTML(text).Length > 500 || CRegex.FilterHTML(text).Length < 6) { rm.Info = "回复内容长度在6~500之间"; return(jss.Serialize(rm)); } else { string strIP = WebHelp.GetIP(); User user = UserDal.CurrentUser();//获取当前登陆用户 List <dbParam> list = new List <dbParam>() { new dbParam() { ParamName = "@ClientIP", ParamValue = strIP }, new dbParam() { ParamName = "@UserId", ParamValue = user.UserId } }; #region 一IP,同一当前日期(年月日),可以确定当天回复次数。 List <WebCommentReply> wcrList = CommentReplyDAL.m_WebCommentReplyDAL.GetList(" ClientIP=@ClientIP and UserId=@UserId", list); int count = 0; if (wcrList.Count == 0) { count = 0; } else { string DateCurrent = string.Format("{0:D}", DateTime.Now);//设置当前日期(年-月-日) foreach (var wcr in wcrList) { if (DateCurrent == string.Format("{0:D}", wcr.CreatedTime)) { count++; } } } #endregion //同一用户不能一天超过三次留言 if (count >= 3) { rm.Info = "一天最多只能回复三次"; jss.Serialize(rm); } else { if (user.Type < 0) { rm.Info = "只有已登录用户用户才能评论"; jss.Serialize(rm); } else { WebCommentReply webComReply = new WebCommentReply(); webComReply.WebCommentId = webCommentId; webComReply.UserId = user.UserId; webComReply.CommentReplyText = text; webComReply.CreatedTime = DateTime.Now; webComReply.ClientIP = WebHelp.GetIP(); CommentReplyDAL.m_WebCommentReplyDAL.Add(webComReply); rm.Success = true; rm.Info = "评论成功"; } } } return(jss.Serialize(rm)); }
public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string xuehao = context.Request.Form["xuehao"]; string realname = context.Request.Form["realname"]; string email = context.Request.Form["email"]; string pwd = context.Request.Form["pwd"]; int sex = int.Parse(context.Request.Form["sex"]); string invitecode = context.Request.Form["invitecode"]; string avatar = "default.png"; if (xuehao == "" || realname == "" || email == "" || pwd == "" || sex == 0) { context.Response.Write("empty"); } else { List <dbParam> list = new List <dbParam>() { new dbParam { ParamName = "@xuehao", ParamValue = xuehao }, new dbParam { ParamName = "@realname", ParamValue = realname }, new dbParam { ParamName = "@email", ParamValue = email } }; if (UserInforDAL.m_UserInforDAL.Exists("Xuehao=@xuehao and Realname=@realname and Uemail=@email", list)) { context.Response.Write("same"); } else { UserInfor user = new UserInfor(); user.Xuehao = xuehao; user.Realname = realname; user.Nickname = null; user.Uemail = email; user.password = pwd; user.Sex = sex; string NowYear = DateTime.Now.ToString("yyyy"); string NowMouth = DateTime.Now.ToString("MM"); string NowDay = DateTime.Now.ToString("dd"); if (NowMouth.Length == 1) { NowMouth = "0" + NowMouth; } if (NowDay.Length == 1) { NowDay = "0" + NowDay; } string NowTime = NowYear + "年" + NowMouth + "月" + NowDay + "日"; user.CreatedTime = NowTime; user.Uavatar = avatar; user.UIdentity = "2"; user.Ucash = 0; user.RegIP = WebHelp.GetIP(); user.LoginIP = WebHelp.GetIP(); if (UserInforDAL.m_UserInforDAL.Add(user) > 0) { context.Response.Write("ok"); } else { context.Response.Write("no"); } } } }