Ejemplo n.º 1
0
        /// <inheritdoc/>
        public override async Task RemoveFromRoleAsync(TUser user, string normalizedRoleName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            user.ThrowIfNull(nameof(user));
            if (string.IsNullOrEmpty(normalizedRoleName))
            {
                throw new ArgumentException(nameof(normalizedRoleName));
            }
            var roleEntity = await FindRoleAsync(normalizedRoleName, cancellationToken);

            if (roleEntity != null)
            {
                var userRoles = (await UserRolesTable.GetRolesAsync(user.Id))?.Select(x => new TUserRole {
                    UserId = user.Id,
                    RoleId = x.Id
                }).ToList();
                UserRoles = userRoles;
                var userRole = await FindUserRoleAsync(user.Id, roleEntity.Id, cancellationToken);

                if (userRole != null)
                {
                    UserRoles.Remove(userRole);
                }
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        protected override async Task <TUserRole> FindUserRoleAsync(TKey userId, TKey roleId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            var userRole = await UserRolesTable.FindUserRoleAsync(userId, roleId);

            return(userRole);
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public override async Task <IList <string> > GetRolesAsync(TUser user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            user.ThrowIfNull(nameof(user));
            var userRoles = await UserRolesTable.GetRolesAsync(user.Id);

            return(userRoles.Select(x => x.Name).ToList());
        }
Ejemplo n.º 4
0
 public UserStore(IDatabaseConnectionFactory databaseConnectionFactory)
 {
     _usersTable       = new UsersTable(databaseConnectionFactory);
     _usersRolesTable  = new UserRolesTable(databaseConnectionFactory);
     _rolesTable       = new RolesTable(databaseConnectionFactory);
     _usersClaimsTable = new UserClaimsTable(databaseConnectionFactory);
     _usersLoginsTable = new UserLoginsTable(databaseConnectionFactory);
     _userTokensTable  = new UserTokensTable(databaseConnectionFactory);
 }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public override async Task AddToRoleAsync(TUser user, string normalizedRoleName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            user.ThrowIfNull(nameof(user));
            if (string.IsNullOrEmpty(normalizedRoleName))
            {
                throw new ArgumentException($"Parameter {nameof(normalizedRoleName)} cannot be null or empty.");
            }
            var roleEntity = await FindRoleAsync(normalizedRoleName, cancellationToken);

            if (roleEntity == null)
            {
                throw new InvalidOperationException($"Role '{normalizedRoleName}' was not found.");
            }
            var userRoles = (await UserRolesTable.GetRolesAsync(user.Id))?.Select(x => new TUserRole {
                UserId = user.Id,
                RoleId = x.Id
            }).ToList();

            UserRoles = userRoles;
            UserRoles.Add(CreateUserRole(user, roleEntity));
        }