public async Task<JsonResult> SetPhoneNumber(SetPhoneNumberAddressModel model) { var accessToken = await _dbContext .AccessToken .SingleOrDefaultAsync(t => t.Value == model.AccessToken); var app = await _developerApiService.AppInfoAsync(accessToken.ApplyAppId); var targetUser = await _dbContext.Users.FindAsync(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!" }); } if (!app.App.ChangePhoneNumber) { return this.Protocal(ErrorType.Unauthorized, "You app is not allowed to set users' phone number."); } if (string.IsNullOrWhiteSpace(model.Phone)) { targetUser.PhoneNumber = string.Empty; } else { targetUser.PhoneNumber = model.Phone; } await _userManager.UpdateAsync(targetUser); return this.Protocal(ErrorType.Success, "Successfully set the user's PhoneNumber!"); }
public async Task<JsonResult> SetPhoneNumber(SetPhoneNumberAddressModel model) { var user = await _grantChecker.EnsureGranted(model.AccessToken, model.OpenId, t => t.ChangePhoneNumber); if (string.IsNullOrWhiteSpace(model.Phone)) { user.PhoneNumber = string.Empty; } else { user.PhoneNumber = model.Phone; } await _userManager.UpdateAsync(user); return this.Protocol(ErrorType.Success, "Successfully set the user's PhoneNumber!"); }