public async Task <IActionResult> ViewAllEmails(ViewAllEmailsAddressModel model) { var accessToken = await _dbContext .AccessToken .SingleOrDefaultAsync(t => t.Value == model.AccessToken); var app = await ApiService.AppInfoAsync(accessToken.ApplyAppId); var targetUser = await _dbContext.Users.Include(t => t.Emails).SingleOrDefaultAsync(t => t.Id == model.OpenId); if (targetUser == null) { return(this.Protocal(ErrorType.NotFound, "Could not find target user.")); } if (!_dbContext.LocalAppGrant.Exists(t => t.AppID == accessToken.ApplyAppId && t.APIUserId == targetUser.Id)) { return(Json(new AiurProtocal { Code = ErrorType.Unauthorized, Message = "This user did not grant your app!" })); } return(Json(new AiurCollection <IUserEmail>(targetUser.Emails) { Code = ErrorType.Success, Message = "Successfully get the target user's emails." })); }
public async Task<IActionResult> ViewAllEmails(ViewAllEmailsAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, null); var emails = await _dbContext.UserEmails.Where(t => t.OwnerId == user.Id).ToListAsync(); return Json(new AiurCollection<UserEmail>(emails) { Code = ErrorType.Success, Message = "Successfully get the target user's emails." }); }