public IActionResult SingIn([FromBody] SingIn paras) { //是否启用验证码 if (_redisCommon.GetValue("OnLoginVerify") == "1") { var cache = HttpContext.Session.GetString("verify"); if (string.IsNullOrEmpty(cache)) { throw ExceptionEnum.Parameter.ToEx("验证码失效"); } if (!(paras.Verify ?? "").ToLower().Equals(cache.ToLower())) { throw ExceptionEnum.Parameter.ToEx("验证码错误"); } HttpContext.Session.Clear(); } //验证账户 var model = _dbContext.SystemUser.FirstOrDefault(m => m.Code == paras.Code); if (model == null) { throw ExceptionEnum.Operating.ToEx("用户不存在"); } var mix = (paras.Code + paras.Password).ToMd5(); if (model.Password != mix) { throw ExceptionEnum.Operating.ToEx("密码错误"); } if (model.Status != 1) { throw ExceptionEnum.Disable.ToEx("账户被禁用或已删除"); } //登录记录 _dbContext.LoginRecord.Add(new LoginRecord() { Address = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString(), LoginTime = DateTime.Now, UserId = model.Id, LoginType = 1 }); _dbContext.SaveChanges(); var result = new { Token = GetToken(model), Id = model.Id, Name = model.Name, Code = model.Code, Image = model.Image, Level = model.Level, Status = model.Status, Roles = model.Roles, }; return(Json(result.ToSuccess())); }
public IActionResult Edit([FromBody] ConfigEdit paras) { var has = _dbContext.SystemConfig.FirstOrDefault(m => m.Key == paras.Key && m.Id != paras.Id); if (has != null) { throw ExceptionEnum.Operating.ToEx("键已存在"); } SystemConfig config = new SystemConfig() { Id = paras.Id.Value, Key = paras.Key, Memo = paras.Memo, Name = paras.Name, Status = paras.Status.Value, Value = paras.Value }; _dbContext.SystemConfig.Update(config); int result = _dbContext.SaveChanges(); return(Json((result > 0).ToResult())); }