public async Task <JsonResult> IsValidApp(IsValidateAppAddressModel model) { if (!_cache.TryGetValue(model.AppId, out App target)) { target = await _dbContext.Apps.FindAsync(model.AppId); var cacheEntryOptions = new MemoryCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromMinutes(20)); _cache.Set(model.AppId, target, cacheEntryOptions); } if (target == null) { return(Json(new AiurProtocol { Message = "Target app did not found.", Code = ErrorType.NotFound })); } else if (target.AppSecret != model.AppSecret) { return(Json(new AiurProtocol { Message = "Wrong secret.", Code = ErrorType.WrongKey })); } else { return(Json(new AiurProtocol { Message = "Correct app info.", Code = ErrorType.Success })); } }
public async Task <JsonResult> IsValidApp(IsValidateAppAddressModel model) { if (!ModelState.IsValid) { return(Json(new AiurProtocal { message = "Wrong input.", code = ErrorType.InvalidInput })); } var _target = await _dbContext.Apps.FindAsync(model.AppId); if (_target == null) { return(Json(new AiurProtocal { message = "Target app did not found.", code = ErrorType.NotFound })); } else if (_target.AppSecret != model.AppSecret) { return(Json(new AiurProtocal { message = "Wrong secret.", code = ErrorType.WrongKey })); } else { return(Json(new AiurProtocal { message = "Correct app info.", code = ErrorType.Success })); } }
public async Task <IActionResult> IsValidateApp(IsValidateAppAddressModel model) { if (!ModelState.IsValid) { return(Json(new AiurProtocal { message = "Wrong input.", code = -10 })); } var _target = await _dbContext.Apps.SingleOrDefaultAsync(t => t.AppId == model.AppId); if (_target == null) { return(Json(new AiurProtocal { message = "Not found.", code = -4 })); } if (_target.AppSecret != model.AppSecret) { return(Json(new AiurProtocal { message = "Wrong secret.", code = -1 })); } return(Json(new AiurProtocal { message = "Currect", code = 0 })); }
public async Task <JsonResult> IsValidApp(IsValidateAppAddressModel model) { var target = await _cache.GetAndCache(model.AppId, async() => await _dbContext.Apps.FindAsync(model.AppId)); if (target == null) { return(Json(new AiurProtocol { Message = "Target app did not found.", Code = ErrorType.NotFound })); } else if (target.AppSecret != model.AppSecret) { return(Json(new AiurProtocol { Message = "Wrong secret.", Code = ErrorType.WrongKey })); } else { return(Json(new AiurProtocol { Message = "Correct app info.", Code = ErrorType.Success })); } }