public ActionResult Login(FormCollection fc) { bool error = false; string userName = fc["txtUserName"]; string userPwd = fc["txtUserPwd"]; if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(userPwd)) { error = true; ModelState.AddModelError("UserNameOrUserPwdEmpty", "用户名或密码不能为空!"); } if (!error && ModelState.IsValid) { //判断用户是否存在 //判断密码是否正确 if (!OrderAdminService.IsExistsUserName(userName)) { ModelState.AddModelError("UserNameNotExists", "用户名不存在,请重试!"); } else if (!OrderAdminService.ValidateForLogin(userName, userPwd)) { ModelState.AddModelError("UserPwdError", "密码错误,请重试!"); } else { //正确 var userInfo = OrderAdminService.Get(userName); string _cookieValue = string.Format("{0}#{1}", userInfo.UserName, userInfo.RoleType); //MD5加密 _cookieValue = Goodspeed.Library.Security.DESCryptography.Encrypt(_cookieValue, System.Configuration.ConfigurationManager.AppSettings["DESKey"]); //Write cookie Controleng.Common.Utils.WriteCookie(OrdersAdminContext.LOGINCOOKIEKEY, _cookieValue, COOKIEEXPIRETIME); Response.Redirect("/"); } } return(View()); }
public ActionResult Add(OrderAdminInfo model, FormCollection fc) { bool error = false; string roleType = fc["ddlRoles"]; if (OrderAdminService.IsExistsUserName(model.UserName)) { error = true; ModelState.AddModelError("UserNameExists", "用户名已存在,请选择其他用户名!"); } if (string.IsNullOrEmpty(roleType)) { error = true; ModelState.AddModelError("RoleType", "请选择管理权限!"); } if (!error && ModelState.IsValid) { model.RoleType = (OrderAdminRoleType)Enum.Parse(typeof(OrderAdminRoleType), roleType); OrderAdminService.Add(model); ModelState.AddModelError("Success", "添加成功!"); } return(View()); }