/// <summary> /// 登录 /// </summary> /// <returns></returns> public JsonResult Login() { var resultMsg = ""; var userName = HttpContext.Request.Form["userName"]; var password = HttpContext.Request.Form["password"]; if (userName != null) { var model = uBll.GetByAccount(userName); if (model == null) { resultMsg = "用户不存在"; } else { var encryPass = Md5Encoding.Encoding(password); if (!encryPass.Equals(model.Password)) { resultMsg = "密码错误"; } else { HttpCookie cookie = new HttpCookie("platform"); cookie.Values.Add("account", userName.Trim()); cookie.Values.Add("password", password.Trim()); cookie.Expires = System.DateTime.Now.AddDays(7.0); HttpContext.Response.Cookies.Add(cookie); Session["userId"] = model.UserID; Session["userName"] = model.LoginName; Session["realName"] = model.Username; resultMsg = "success"; } } } else { resultMsg = "请输入用户名"; } return(Json(resultMsg, JsonRequestBehavior.AllowGet)); }
public JsonResult Register() { var resultMsg = ""; var hidId = Request.Form["HidUId"]; var userName = HttpContext.Request.Form["txtRealName"]; var loginName = Request.Form["txtloginName"]; var password = Request.Form["txtPassword"]; var mobile = Request.Form["txtTel"]; var email = Request.Form["txtEmail"]; var userType = Request.Form["userType"]; var address = Request.Form["txtAddress"]; if (hidId.IsNullOrEmpty()) { var model = uBll.GetByAccount(userName); if (model != null) { resultMsg = "当前用户已存在!"; } else { var pp = new Users() { UserID = Guid.NewGuid(), Username = userName, LoginName = loginName, Password = Md5Encoding.Encoding(password), Mobile = mobile, Email = email, Address = address, UserType = userType, CreateTime = DateTime.Now, ModifyTime = DateTime.Now, CreateBy = Session["userName"] != null ? Session["userName"].ToString() : "" }; var rst = uBll.Insert(pp); if (rst > 0) { resultMsg = "success"; } else { resultMsg = "error"; } } } else { var uu = uBll.GetById(hidId.ToGuid()); uu.LoginName = loginName; uu.Username = userName; uu.Mobile = mobile; uu.Email = email; uu.Address = address; uu.UserType = userType; uu.ModifyTime = DateTime.Now; uu.ModifyBy = Session["userName"] != null ? Session["userName"].ToString() : ""; var rst = uBll.Update(uu); if (rst > 0) { resultMsg = "success"; } else { resultMsg = "error"; } } return(Json(resultMsg, JsonRequestBehavior.AllowGet)); }