public ActionResult Login(string Username, string Password, string ReturnUrl) { AjaxModel model = new AjaxModel(); IBLL.IUserBLL bll = BLLSessionFactory.GetBLLSession().IUserBLL; User user = new User(); Password = Encryt.GetMD5(Password.Trim()); user = bll.Login(Username.Trim(), Password); if (user == null) { model.Data = user; model.Msg = "用户名或者密码不正确!"; model.Statu = "err"; } else { FormsAuthentication.SetAuthCookie(Username.Trim(), false); model.Data = user; model.Statu = "ok"; model.BackUrl = ReturnUrl == null ? "/Home/Index" : ReturnUrl; log.Info(new LogContent(Username + ":登陆", LogType.记录.ToString(), HttpHelper.GetIPAddress())); } return(Json(model)); }
public ActionResult Login(FormCollection form) { AjaxMsgModel ajaxM = new AjaxMsgModel() { Statu = "error", Msg = "登录失败!" }; Base_Log logEntity = new Base_Log(); //1.1 获取数据 string strName = Request.Params["UserName"]; string strPwd = Request.Params["Password"]; string vcode = Request.Params["VCode"]; bool isAllway = bool.Parse(Request.Params["isAllway"]); logEntity.CategoryId = 1; logEntity.OperateTypeId = ((int)OperationType.Login).ToString(); logEntity.OperateType = EnumAttribute.GetDescription(OperationType.Login); logEntity.OperateAccount = strName; logEntity.OperateUserId = strName; logEntity.Module = "我的MVC"; ////1.2 验证 //if (vcode!=Session["vcode"].ToString().ToLower()) //{ // ajaxM.Msg = "登录失败,验证码不正确!"; // return Json(ajaxM); //} // 1.3 通过操作上下文获取 用户业务接口对象 ,调用里面的登录方法! User usr = _userBLL.Login(strName, strPwd); if (usr != null) { //2.1 保存 用户数据(session or cookie) Session["ainfo"] = usr; //如果选择了复选框 则要使用cookie 保存数据 if (isAllway) { //2.1.2 将用户id加密成字符串 string strCookieValue = SecurityHelper.EncryptUserInfo(usr.ID.ToString()); //2.1.3 创建cookie HttpCookie cookie = new HttpCookie("cookieId", strCookieValue); cookie.Expires = DateTime.Now.AddDays(1); cookie.Path = "/admin"; Response.Cookies.Add(cookie); //记录登录cookie } //2.2 查询当前用户的权限 , 并将权限存入Session 中 //List<tbMenu> listPers = OperateContext.GetUserPermission(usr.ID); //Session["tbMenu"] = listPers; ajaxM.Statu = "ok"; ajaxM.Msg = "登录成功!"; ajaxM.BackUrl = "/Home/Index";//"/Login/LoginOK"; logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logEntity.WriteLog(); return(Json(ajaxM)); } else { ajaxM.Msg = "登录失败,用户或密码不正确!"; return(Json(ajaxM)); } }