/// <summary> /// 根据用户信息生成加密cookie验证字符串 /// </summary> /// <param name="u"></param> /// <returns></returns> public static string GenLoginFlagStr(U_UserInfo u) { StringBuilder s = new StringBuilder(); s.Append(u.UserId.ToString()); s.Append(u.Email); s.Append(u.Password); return s.ToString().ToMd5(); }
/// <summary> /// 格式化“回复消息” /// </summary> /// <returns></returns> public static string GetReplyMsg(M_Message msg,U_UserInfo sender) { string m = string.Empty; m = string.Format( "\r\n\r\n\r\n{3}以下是历史消息{3}\r\n{0},原发件人:{1}\r\n\r\n{2}", msg.CreateTime.ToString(),sender.TmmDispName,msg.Content, ConfigHelper.MsgSepChar); return m; }
public void DoLogin(string email,string password,string backUrl,bool isRemember) { email = email ?? string.Empty; password = password ?? string.Empty; password = password.ToMd5(); try { UserService us = Context.GetService<UserService>(); U_UserInfo logonUser = us.UserInfoBll.FindUserByLogin(email, password); if (logonUser != null) { //写cookies HttpCookie cookie = new HttpCookie("tmm"); cookie["UserId"] = logonUser.UserId.ToString(); cookie["Flag"] = Utils.TmmUtils.GenLoginFlagStr(logonUser); cookie.Path = "/"; if (isRemember) { cookie.Expires = DateTime.Now + new TimeSpan(30, 0, 0, 0); //生存期30天 } HttpContext.Response.Cookies.Add(cookie); Session["logonUser"] = logonUser; if (!string.IsNullOrEmpty(backUrl.ToUrlDecode())) { Redirect(backUrl); return; } Redirect("/home/MyDefault.do"); return; } else { AddError("登陆失败,请检查用户名或密码"); } } catch { AddError("系统错误,请重试"); } Flash["userInfo"] = new U_UserInfo() { Email=email}; RedirectToReferrer(); }
/// <summary> /// 更新数据 /// </summary> /// <param name="obj"></param> /// <returns>返回:ture 成功,false 失败</returns> public bool Update(U_UserInfo obj) { return dal.Update(obj); }
/// <summary> /// 插入数据 /// </summary> /// <param name="obj">对象</param> /// <returns>返回:该条数据的主键Id</returns> public int Insert(U_UserInfo obj) { return dal.Insert(obj); }
public void DoQQLogin(string nickName,string headImg) { nickName = Context.Server.UrlDecode(nickName); headImg = Context.Server.UrlDecode(headImg); var token = Request.ReadCookie("qq_openid"); TMM.Core.Utils.Log4Net.Error(string.Format("获取openid:{0}",token)); UserService userService = Context.GetService<UserService>(); var existUser = userService.UserInfoBll.FindUserByOpenId(token); if (existUser == null) { var userInfo = new U_UserInfo(); userInfo.NickName = nickName; userInfo.RegTime = DateTime.Now; userInfo.RegIp = Context.Request.UserHostAddress; userInfo.RegFrom = (int)TMM.Model.Enums.RegType.OAuthQQ; userInfo.OpenId = token; userInfo.Email = string.Format("{0}@qq.com",nickName); userInfo.Password = token; userInfo.HeadIcon = headImg; userInfo.UserId = userService.UserInfoBll.Insert(userInfo); TMM.Core.Utils.Log4Net.Error(string.Format("插入用户获取ID:{0}",userInfo.UserId)); //写cookie HttpCookie cookie = new HttpCookie("tmm"); cookie["UserId"] = userInfo.UserId.ToString(); cookie["Flag"] = Utils.TmmUtils.GenLoginFlagStr(userInfo); cookie.Path = "/"; HttpContext.Response.Cookies.Add(cookie); Session["logonUser"] = userInfo; } else { HttpCookie cookie = new HttpCookie("tmm"); cookie["UserId"] = existUser.UserId.ToString(); cookie["Flag"] = Utils.TmmUtils.GenLoginFlagStr(existUser); cookie.Path = "/"; HttpContext.Response.Cookies.Add(cookie); Session["logonUser"] = existUser; } Redirect("/home/mydefault.do"); }
protected void CheckOrder(TOrder m, OrderStatus[] status,U_UserInfo u) { if (m == null) throw new Exception("无效的订单"); bool checkStatus = false; foreach (OrderStatus os in status) { if (m.Status == (int)os) { checkStatus = true; break; } } if (!checkStatus) throw new Exception("错误的订单状态"); if (m.UserId != u.UserId) throw new Exception("请从正确的地址访问"); }