diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index 7c08ce00..35b03a37 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -63,11 +63,7 @@ namespace Infrastructure.Web { if (!this.Env.IsDevelopment()) { - services.AddResponseCompression(options => - { - options.Providers.Add(); - options.Providers.Add(); - }); + services.AddResponseCompression(); } services.AddTransient(); services.AddTransient(); diff --git a/projects/IoTCenter/Api/ProjectController.cs b/projects/IoTCenter/Api/ProjectController.cs index b405c8af..07b82725 100644 --- a/projects/IoTCenter/Api/ProjectController.cs +++ b/projects/IoTCenter/Api/ProjectController.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using System; +using System.ComponentModel.DataAnnotations; using System.Linq; namespace IoTCenter.Api.Controllers @@ -42,31 +43,28 @@ namespace IoTCenter.Api.Controllers } [HttpGet] - public IActionResult Update(string userName, string realName, string organName, string organNumber, long timestamp, string role,string token) + public IActionResult Update([Required] string userName, string realName, [Required] string organName, string organNumber, [Required] long timestamp, string role, [Required] string token) { - if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(organName)) - { - var message = "参数不能为空"; - this.logger.LogError(message); - return Problem(message); - } try { var query = this.Request.QueryString.ToString().RemoveParam("token").TrimStart('?').Trim(); var token2 = $"{query},123456".Md5(); if (token2 != token) { - var message = "token无效"; - this.logger.LogError(message); - throw new Exception(message); + ModelState.AddModelError(nameof(token), $"{nameof(token)}无效"); + } + else + { + var sendTime = DateTimeOffset.FromUnixTimeSeconds(timestamp); + var seconds = (DateTime.UtcNow - sendTime).TotalSeconds; + if (seconds > 60) + { + ModelState.AddModelError(nameof(timestamp), $"timestamp超时{seconds}秒,已过期"); + } } - var sendTime = DateTimeOffset.FromUnixTimeSeconds(timestamp); - var seconds = (DateTime.UtcNow - sendTime).TotalSeconds; - if (seconds>60) + if (!ModelState.IsValid) { - var message = $"timestamp差距{seconds}秒"; - this.logger.LogError(message); - throw new Exception(message); + return ValidationProblem(); } var organ = this._organRepo.Table().FirstOrDefault(o => o.Name == organName); if (organ == null) @@ -117,7 +115,6 @@ namespace IoTCenter.Api.Controllers } } } - } catch (Exception ex) { diff --git a/projects/IoTCenter/appsettings.Development.json b/projects/IoTCenter/appsettings.Development.json index 75615d6e..f0cd2eae 100644 --- a/projects/IoTCenter/appsettings.Development.json +++ b/projects/IoTCenter/appsettings.Development.json @@ -1,5 +1,5 @@ { "AppSettings": { - "database": "mysql" + "database": "sqlite" } } \ No newline at end of file diff --git a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs index bb347ce1..6c9dcbf8 100644 --- a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs +++ b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs @@ -98,11 +98,15 @@ namespace UserCenter.Areas.Admin.Controllers } if (this.Repo.ReadOnlyTable().Any(o => o.Email == model.Email)) { - ModelState.AddModelError(o => model.UserName, "Ѿ"); + ModelState.AddModelError(o => model.Email, "Ѿ"); + } + if (!string.IsNullOrEmpty(model.PhoneNumber)&&this.Repo.ReadOnlyTable().Any(o => o.PhoneNumber == model.PhoneNumber)) + { + ModelState.AddModelError(o => model.Email, "ֻѾ"); } if (this.Repo.ReadOnlyTable().Any(o => o.NickName == model.NickName)) { - ModelState.AddModelError(o => model.UserName, "dzѾ"); + ModelState.AddModelError(o => model.NickName, "dzѾ"); } return base.Add(model); }