public ActionResult Edit([FromForm] SystemUserEdit model) { if (model.Id == 1) { return(Json(ResponseHelper.Error("该用户不可被编辑"))); } if (!string.IsNullOrEmpty(model.Pwd)) { if (model.Pwd.Length < 6 || model.Pwd.Length > 16) { return(Json(ResponseHelper.Error("密码长度不能少于6位大于16位!"))); } } var UserModel = SystemUserHelper.GetModel(model.Id); //查询是否存重名 if (SystemUserHelper.Exists(p => p.Id != model.Id && (p.Phone.Equals(model.Phone) || p.Email.Equals(model.Email)))) { return(Json(new { status = 0, msg = "已存在相同的手机号或者邮箱,请修改!" })); } UserModel.Email = model.Email; UserModel.Status = model.IsUse; UserModel.NickName = model.Name; UserModel.Phone = model.Phone; if (!string.IsNullOrEmpty(model.Pwd)) { UserModel.Password = AESUtil.Md5(model.Pwd); } SystemUserHelper.Update(UserModel); return(Json(ResponseHelper.Success("ok"))); }
public ActionResult SignIn([FromForm] SignInModel model) { try { var UserString = HttpContext.Session.GetString("UserInfo"); if (!string.IsNullOrEmpty(UserString)) { return(Json(ResponseHelper.Success(JsonConvert.DeserializeObject <SessionUser>(UserString)))); } // TODO: Add login logic here var password = AESUtil.Md5(model.Password); var user = SystemUserHelper.GetModel(p => p.Password == password && (p.Email == model.Account || p.Account == model.Account || p.Phone == model.Account)); if (user == null) { return(Json(ResponseHelper.Error("账户或密码错误,请确认后再试!"))); } if (user.Status != SystemUser_Status_Enum.正常) { return(Json(ResponseHelper.Error("账户已被冻结!"))); } //获取用户角色 var role = SystemUserRoleMappingHelper.GetRoleBy(user.Id); if (role == null) { return(Json(ResponseHelper.Error("该账户还未分配角色请联系管理员!"))); } var roleAuthList = RoleAuthMappingHelper.GetList(p => p.RoleId == role.Id); if (roleAuthList.Count < 1) { return(Json(ResponseHelper.Error("角色未拥有权限,请联系下管理员处理"))); } var token = Guid.NewGuid().ToString("N"); //存session var UserCache = new SessionUser { HeadImg = user.HeadImage, Token = token, UId = user.Id.ToString(), UserName = user.NickName, RoleId = role.Id, Email = user.Email, RoleName = role.Name, AuthMenu = roleAuthList.Select(p => p.MenuId).ToList() }; HttpContext.Session.SetString("UserInfo", JsonConvert.SerializeObject(UserCache)); //返回用户信息 return(Json(ResponseHelper.Success(UserCache))); } catch { return(View()); } }
public ActionResult Create([FromForm] SystemUserCreate model) { if (SystemUserHelper.Exists(p => p.NickName == model.Name || p.Phone == model.Phone || p.Email == model.Email)) { return(Json(ResponseHelper.Error("该用户已经存在!"))); } var UserModel = new SystemUser { Account = model.Account, CreatedTime = DateTime.Now, Email = model.Email, HeadImage = "", NickName = model.Name, Password = AESUtil.Md5(model.Pwd), Phone = model.Phone, Status = model.IsUse }; SystemUserHelper.Insert(UserModel); return(Json(ResponseHelper.Success("ok"))); }