private void SetAuthCookie(CurrentVipModel user) { var userInfo = user.ToJson(); var cookie = new HttpCookie("webAuthData"); cookie.Value = EncryptHelper.DESEncrypt(userInfo, ConfigurationManager.AppSettings["authKey"]); cookie.Expires = DateTime.Now.AddDays(3); cookie.Path = "/"; cookie.HttpOnly = true; Response.Cookies.Remove("webAuthData"); Response.Cookies.Add(cookie); }
public ActionResult Login(string mobile, string password) { ViewBag.Title = "登录"; if (string.IsNullOrEmpty(mobile) || string.IsNullOrEmpty(password)) { ViewBag.Error = "手机号或密码为空"; return(View()); } var user = _dal.GetByMobile(mobile); if (user == null || user.Password != password) { ViewBag.Error = "手机号或密码错误"; return(View()); } if (string.IsNullOrEmpty(user.WeChatId)) { OAuthHelper.DoOAuth(HttpContext, mobile); return(new EmptyResult()); } var userInfo = new CurrentVipModel { VipId = user.Id, OpenId = user.WeChatId, pwd = EncryptHelper.Md5(password) }; SetAuthCookie(userInfo); HttpContext.Items["CurrentVip"] = userInfo; return(RedirectToAction("Index", "User")); }