public ActionResult ModifyPassword(string oldPwd, string newPwd, string confirmPwd) { SysUserInfo ui = Startup.GetUserInfo(); string code = ""; string msg = ""; EncryptCommon EncryptCommon = new EncryptCommon(); if (EncryptCommon.EncryptMD5(oldPwd) == ui.Password) { if (newPwd == confirmPwd) { SysUserInfoMan uiMan = new SysUserInfoMan(); SysUserInfo user = uiMan.GetEntity(ui.ID); user.Password = EncryptCommon.EncryptMD5(newPwd); user.UpdateTime = DateTime.Now; ui.Password = user.Password; uiMan.Update(user); code = "1"; msg = "修改成功"; } else { code = "2"; msg = "重设密码与确认密码输入不一致!"; } } else { code = "2"; msg = "原始密码输入错误!"; } ViewBag.code = code; ViewBag.msg = msg; return(View()); }
public ActionResult Login(string userName, string passWord, string imgCode) { if (string.IsNullOrWhiteSpace(userName)) { return(Json(new { Msg = "请输入用户名", code = 400 })); } if (string.IsNullOrEmpty(passWord)) { return(Json(new { Msg = "请输入密码", code = 401 })); } if (imgCode != "1111")//添加万能验证码方便自动化测试 { if (string.IsNullOrEmpty(imgCode) || Session["img_vcode"] == null || imgCode.ToLower() != Session["img_vcode"].ToString().ToLower()) { return(Json(new { Msg = "验证码输入错误", code = 402 })); } } var userMan = new SysUserInfoMan(); var user = userMan.GetModelByUserName(userName); if (user == null) { return(Json(new { Msg = "用户名或密码错误", code = 403 })); } if (user.Password != EncryptCommon.EncryptMD5(passWord)) { return(Json(new { Msg = "用户名或密码错误", code = 404 })); } Startup.SaveUserInfo(user); //return View("Index"); return(Json(new { Msg = "登陆成功", code = 200 })); }
public ActionResult Add(FarmMonitor.Model.SysUserInfo model, string roleinfoName) { if (string.IsNullOrEmpty(model.Name)) { return(Content("<script>alert('名字不能为空');window.location.href='/UserInfoManage/Add/'</script>")); } if (string.IsNullOrEmpty(model.Password)) { return(Content("<script>alert('密码不能为空';window.location.href='/UserInfoManage/Add/')</script>")); } if (string.IsNullOrEmpty(model.Tel) && string.IsNullOrEmpty(model.Mobile)) { return(Content("<script>alert('电话和手机不能为空');window.location.href='/UserInfoManage/Add/'</script>")); } if (string.IsNullOrEmpty(model.Province.ToString()) || string.IsNullOrEmpty(model.City.ToString())) { return(Content("<script>alert('省份城市不能为空');window.location.href='/UserInfoManage/Add/'</script>")); } var usero = userinfoman.GetModelByUserName(model.Name); if (usero != null) { return(Content("<script>alert('用户名重复');window.location.href='/UserInfoManage/Add/'</script>")); } #region 增加用户信息 userinfo.Name = model.Name; userinfo.Password = EncryptCommon.EncryptMD5(model.Password); userinfo.UserCode = model.UserCode; userinfo.Sex = model.Sex; userinfo.Tel = model.Tel == null ? "" : model.Tel; userinfo.Birthday = model.Birthday; userinfo.Province = model.Province; userinfo.City = model.City; userinfo.Mobile = model.Mobile == null ? "" : model.Mobile; userinfo.Email = model.Email == null ? "" : model.Email; userinfo.UserState = model.UserState; userinfo.Remark = model.Remark == null ? "" : model.Remark; userinfo.CreateDate = DateTime.Now; userinfoman.Add(userinfo); #endregion #region 增加用户角色关联表 SysUserRoleMan userroleman = new SysUserRoleMan(); SysUserRole userrole = new SysUserRole(); userrole.RoleId = Convert.ToInt32(roleinfoName); userrole.UserId = userinfo.ID; userrole.CreateTime = DateTime.Now; userroleman.Add(userrole); #endregion return(Content("<script>alert('增加成功');window.location.href='/UserInfoManage/Index/'</script>")); }
public ActionResult Edit(FarmMonitor.Model.SysUserInfo model, string roleinfoName) { if (string.IsNullOrEmpty(model.Name)) { return(Content("<script>alert('名字不能为空');window.location.href='/UserInfoManage/Edit/@model.ID'</script>")); } //if (string.IsNullOrEmpty(model.Password)) //{ // return Content("<script>alert('密码不能为空';window.location.href='/UserInfoManage/Edit/@model.ID')</script>"); //} if (string.IsNullOrEmpty(model.Tel) && string.IsNullOrEmpty(model.Mobile)) { return(Content("<script>alert('电话和手机不能为空');window.location.href='/UserInfoManage/Edit/@model.ID'</script>")); } if (string.IsNullOrEmpty(model.Province.ToString()) || string.IsNullOrEmpty(model.City.ToString())) { return(Content("<script>alert('省份城市不能为空');window.location.href='/UserInfoManage/Add/'</script>")); } var userInfoModel = userinfoman.GetEntity(model.ID); #region 用户信息更新 userInfoModel.Name = model.Name; userInfoModel.UserCode = model.UserCode == null ? "" : model.UserCode; userInfoModel.Sex = model.Sex; userInfoModel.Birthday = model.Birthday; userInfoModel.Tel = model.Tel == null ? "" : model.Tel; userInfoModel.Province = model.Province; userInfoModel.City = model.City; userInfoModel.Mobile = model.Mobile == null ? "" : model.Mobile; userInfoModel.Email = model.Email == null ? "" : model.Email; userInfoModel.UserState = model.UserState; userInfoModel.Remark = model.Remark == null ? "" : model.Remark; if (model.Password != "") { userInfoModel.Password = EncryptCommon.EncryptMD5(model.Password); } userinfoman.Update(userInfoModel); #endregion #region 更新用户角色关联表 SysUserRoleMan userroleman = new SysUserRoleMan(); var userroleModel = userroleman.GetModelByUserId(model.ID); userroleModel.RoleId = Convert.ToInt32(roleinfoName); userroleModel.UserId = model.ID; userroleModel.UpdateTime = DateTime.Now; userroleman.Update(userroleModel); #endregion return(Content("<script>alert('更新成功');window.location.href='/UserInfoManage/Index/'</script>")); }