public ActionResult Login(UserLoginModel userLoginModel) { SetPageSeo("用户登录"); if (!ModelState.IsValid) { return(View()); } List <string> msgList = new List <string>(); string verifyCode = Session["ValidateCode"] as string; if (userLoginModel.VerifyCode != verifyCode) { msgList.Add("验证码输入错误"); } userLoginModel = new UserLoginModel() { VerifyCode = Sanitizer.GetSafeHtmlFragment(userLoginModel.VerifyCode), UserName = Sanitizer.GetSafeHtmlFragment(userLoginModel.UserName), Password = userLoginModel.Password }; var userinfo = userBLL.GetUserInfo(userLoginModel.UserName, Md5.GetMd5(userLoginModel.Password)); if (userinfo != null) { UserInfo user = new UserInfo(userinfo.ID, userinfo.UserName, userinfo.IsAdmin == null?0:1); var userJson = JsonConvert.SerializeObject(user); var ticket = new FormsAuthenticationTicket(1, userinfo.UserName, DateTime.Now, DateTime.Now.AddDays(1), true, userJson); //FormsAuthentication.SetAuthCookie(userLoginModel.UserName, true); string cookieString = FormsAuthentication.Encrypt(ticket); HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieString); authCookie.Expires = ticket.Expiration; authCookie.Path = FormsAuthentication.FormsCookiePath; Response.Cookies.Add(authCookie); bool isAuth = Request.IsAuthenticated; // add log if (user.IsAdmin > 0) { T_UserLog log = new T_UserLog() { AddDate = DateTime.Now, Content = string.Format("{0}于{1}登录系统", user.UserName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), UserID = user.UserID, UserName = user.UserName }; userBLL.AddUserLog(log); } return(RedirectToAction("Profile", "User", null)); } else { msgList.Add("用户名或密码错误"); ViewBag.MsgList = msgList; return(View()); } }
public void AddUserLog(T_UserLog log) { userLogDAL.Add(log); }
public int AddUserLog(T_UserLog log) { db.UserLogs.Add(log); return(db.SaveChanges()); }
public void AddUserLog(T_UserLog log) { userlogData.Add(log); }
public void Add(T_UserLog log) { db.UserLogs.Add(log); }