Former-commit-id: ac931665e14d3ac5b8cba522fd0a910a32ff8bc4
Former-commit-id: e6a12cc7ae6dcd4e2c08fbf10098f1f33532c136
TangShanKaiPing
wanggang 5 years ago
parent fa194317ef
commit aecadea17a

@ -63,11 +63,7 @@ namespace Infrastructure.Web
{
if (!this.Env.IsDevelopment())
{
services.AddResponseCompression(options =>
{
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
});
services.AddResponseCompression();
}
services.AddTransient<SettingService>();
services.AddTransient<ISettingService, CachedSettingService>();

@ -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)
{

@ -1,5 +1,5 @@
{
"AppSettings": {
"database": "mysql"
"database": "sqlite"
}
}

@ -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, "昵称已经存在");
ModelState.AddModelError(o => model.NickName, "昵称已经存在");
}
return base.Add(model);
}

Loading…
Cancel
Save