Esempio n. 1
0
        public override async Task <IList <Claim> > GetClaimsAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default)
        {
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            return(await UserClaims.Where(uc => uc.UserId.Equals(user.Id)).Select(c => c.ToClaim()).ToListAsync(cancellationToken));
        }
Esempio n. 2
0
        //protected Task SaveChanges(CancellationToken cancellationToken) => AutoSaveChanges ? Context.SaveChangesAsync(cancellationToken) : Task.CompletedTask;

        public override async Task <IdentityResult> CreateAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            await DataConnection.InsertAsync(user);

            //await SaveChanges(cancellationToken);
            return(IdentityResult.Success);
        }
Esempio n. 3
0
        public override async Task <IList <UserLoginInfo> > GetLoginsAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            var userId = user.Id;

            return(await UserLogins.Where(l => l.UserId.Equals(userId))
                   .Select(l => new UserLoginInfo(l.LoginProvider, l.ProviderKey, l.ProviderDisplayName)).ToListAsync(cancellationToken));
        }
Esempio n. 4
0
        public override async Task RemoveLoginAsync(IdentityUserNav <TKey> user, string loginProvider, string providerKey,
                                                    CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            var entry = await FindUserLoginAsync(user.Id, loginProvider, providerKey, cancellationToken);

            if (entry != null)
            {
                UserLogins.DataContext.Delete(entry);
            }
        }
Esempio n. 5
0
 public override Task AddLoginAsync(IdentityUserNav <TKey> user, UserLoginInfo login,
                                    CancellationToken cancellationToken = default)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     if (login == null)
     {
         throw new ArgumentNullException(nameof(login));
     }
     UserLogins.DataContext.Insert(CreateUserLogin(user, login));
     return(Task.FromResult(false));
 }
Esempio n. 6
0
        public override async Task <IList <string> > GetRolesAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            var userId = user.Id;
            var query  = from userRole in UserRoles
                         join role in Roles on userRole.RoleId equals role.Id
                         where userRole.UserId.Equals(userId)
                         select role.Name;

            return(await query.ToListAsync(cancellationToken));
        }
Esempio n. 7
0
        public override async Task <IdentityResult> DeleteAsync(IdentityUserNav <TKey> user, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            await DataConnection.DeleteAsync(user);

            //try {
            //  await SaveChanges(cancellationToken);
            //} catch (DbUpdateConcurrencyException) {
            //  return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure());
            //}
            return(IdentityResult.Success);
        }
Esempio n. 8
0
 public override Task AddClaimsAsync(IdentityUserNav <TKey> user, IEnumerable <Claim> claims, CancellationToken cancellationToken = default)
 {
     ThrowIfDisposed();
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     if (claims == null)
     {
         throw new ArgumentNullException(nameof(claims));
     }
     foreach (var claim in claims)
     {
         UserClaims.DataContext.Insert(CreateUserClaim(user, claim));
     }
     return(Task.FromResult(false));
 }
Esempio n. 9
0
        public override async Task AddToRoleAsync(IdentityUserNav <TKey> user, string normalizedRoleName, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (string.IsNullOrWhiteSpace(normalizedRoleName))
            {
                throw new ArgumentException(Resources.ValueCannotBeNullOrEmpty, nameof(normalizedRoleName));
            }
            var roleEntity = await FindRoleAsync(normalizedRoleName, cancellationToken);

            if (roleEntity == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.RoleNotFound, normalizedRoleName));
            }
            UserRoles.DataContext.Insert(CreateUserRole(user, roleEntity));
        }
Esempio n. 10
0
        public override async Task RemoveClaimsAsync(IdentityUserNav <TKey> user, IEnumerable <Claim> claims, CancellationToken cancellationToken = default)
        {
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (claims == null)
            {
                throw new ArgumentNullException(nameof(claims));
            }
            foreach (var claim in claims)
            {
                var matchedClaims = await UserClaims.Where(uc => uc.UserId.Equals(user.Id) && uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToListAsync(cancellationToken);

                foreach (var c in matchedClaims)
                {
                    UserClaims.DataContext.Delete(c);
                }
            }
        }
Esempio n. 11
0
        public override async Task <bool> IsInRoleAsync(IdentityUserNav <TKey> user, string normalizedRoleName, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (string.IsNullOrWhiteSpace(normalizedRoleName))
            {
                throw new ArgumentException(Resources.ValueCannotBeNullOrEmpty, nameof(normalizedRoleName));
            }
            var role = await FindRoleAsync(normalizedRoleName, cancellationToken);

            if (role != null)
            {
                var userRole = await FindUserRoleAsync(user.Id, role.Id, cancellationToken);

                return(userRole != null);
            }
            return(false);
        }
Esempio n. 12
0
        public override async Task ReplaceClaimAsync(IdentityUserNav <TKey> user, Claim claim, Claim newClaim, CancellationToken cancellationToken = default)
        {
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }
            if (newClaim == null)
            {
                throw new ArgumentNullException(nameof(newClaim));
            }
            var matchedClaims = await UserClaims.Where(uc => uc.UserId.Equals(user.Id) && uc.ClaimValue == claim.Value && uc.ClaimType == claim.Type).ToListAsync(cancellationToken);

            foreach (var matchedClaim in matchedClaims)
            {
                matchedClaim.ClaimValue = newClaim.Value;
                matchedClaim.ClaimType  = newClaim.Type;
            }
        }
Esempio n. 13
0
        public override async Task RemoveFromRoleAsync(IdentityUserNav <TKey> user, string normalizedRoleName, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (string.IsNullOrWhiteSpace(normalizedRoleName))
            {
                throw new ArgumentException(Resources.ValueCannotBeNullOrEmpty, nameof(normalizedRoleName));
            }
            var roleEntity = await FindRoleAsync(normalizedRoleName, cancellationToken);

            if (roleEntity != null)
            {
                var userRole = await FindUserRoleAsync(user.Id, roleEntity.Id, cancellationToken);

                if (userRole != null)
                {
                    UserRoles.DataContext.Delete(userRole);
                }
            }
        }
Esempio n. 14
0
 protected override Task <IdentityUserTokenNav <TKey> > FindTokenAsync(IdentityUserNav <TKey> user, string loginProvider, string name, CancellationToken cancellationToken)
 => UserTokens.FirstOrDefaultAsync(x => x.UserId.Equals(user.Id) &&
                                   x.LoginProvider.Equals(loginProvider, StringComparison.OrdinalIgnoreCase) &&
                                   x.Name.Equals(name, StringComparison.OrdinalIgnoreCase), cancellationToken);
Esempio n. 15
0
 protected override Task <IdentityUserTokenNav <TKey> > FindTokenAsync(IdentityUserNav <TKey> user, string loginProvider, string name, CancellationToken cancellationToken)
 => (from ut in UserTokens
         where ut.UserId.Equals(user.Id) &&
     ut.LoginProvider.Equals(loginProvider, StringComparison.OrdinalIgnoreCase) &&
     ut.Name.Equals(name, StringComparison.OrdinalIgnoreCase)
     select ut).FirstOrDefaultAsync(cancellationToken);