public Task RemoveFromRoleAsync(U user, string roleName, CancellationToken cancellationToken) { UserAddendum addendum = s_userAddendums.GetOrCreateValue(user); addendum.Roles.Remove(roleName); return(Task.CompletedTask); }
public async Task <IdentityResult> UpdateAsync(U user, CancellationToken cancellationToken) { _logger.LogDebug("UpdateAsync({0})", user.NormalizedEmail); // Was the NormalizedUserName modified? UserAddendum addendum = s_userAddendums.GetOrCreateValue(user); if (user.NormalizedUserName == addendum.NormalizedUserName) { // NormalizedUserName was not modified. The common and efficient case. return(await Rpc.TranslateExceptionsAsync(() => _datastore.UpsertAsync(UserToEntity(user), CallSettings.FromCancellationToken(cancellationToken)))); } Entity entity = UserToEntity(user); Entity indexEntity = new Entity() { Key = _nnindexKeyFactory.CreateKey(user.NormalizedUserName), [USER_KEY] = entity.Key }; var result = await InTransactionAsync(cancellationToken, async (transaction, callSettings) => { // NormalizedUserName was modified. Have to update the // index too. if (!string.IsNullOrEmpty(addendum.NormalizedUserName)) { transaction.Delete(_nnindexKeyFactory .CreateKey(addendum.NormalizedUserName)); } indexEntity[USER_KEY].ExcludeFromIndexes = true; transaction.Upsert(entity); transaction.Upsert(indexEntity); await transaction.CommitAsync(callSettings); }); if (result.Succeeded) { addendum.NormalizedUserName = user.NormalizedUserName; } return(result); }
public Task <bool> IsInRoleAsync(U user, string roleName, CancellationToken cancellationToken) { UserAddendum addendum = s_userAddendums.GetOrCreateValue(user); return(Task.FromResult(addendum.Roles.Contains(roleName))); }
public Task <IList <string> > GetRolesAsync(U user, CancellationToken cancellationToken) { UserAddendum addendum = s_userAddendums.GetOrCreateValue(user); return(Task.FromResult((IList <string>)addendum.Roles)); }