public async Task <IList <string> > GetRolesAsync(TUser user)
        {
            IMongoCollection <ExtenderUser <TUserId> > userRoleCollection = GetCollection <ExtenderUser <TUserId> >(UserCollectionName);
            ExtenderUser <TUserId> userRoleHolder = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, f => f.Project("Roles"));

            return(userRoleHolder.Roles != null?userRoleHolder.Roles.ToList() : new List <string>());
        }
        public async Task <bool> GetPhoneNumberConfirmedAsync(TUser user)
        {
            IMongoCollection <ExtenderUser <TUserId> > userCollection = GetCollection <ExtenderUser <TUserId> >(UserCollectionName);

            ExtenderUser <TUserId> extendedUser = await userCollection.Find(Builders <ExtenderUser <TUserId> > .Filter.Eq("Id", ((IIdentityUser <TUserId>)user).Id))
                                                  .SingleAsync();

            return(extendedUser.PhoneNumberConfirmed);
        }
        public async Task <IList <UserLoginInfo> > GetLoginsAsync(TUser user)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync
                                                  (
                ((IIdentityUser <TUserId>)user).Id,
                find =>
            {
                find.Project("Logins");
            }
                                                  );

            return(extendedUser.Logins.ToList());
        }
        public async Task RemoveFromRoleAsync(TUser user, string roleName)
        {
            IMongoCollection <ExtenderUser <TUserId> > userRoleCollection = GetCollection <ExtenderUser <TUserId> >(UserCollectionName);
            ExtenderUser <TUserId> userRoleHolder = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, f => f.Project("Roles"));

            if (userRoleHolder.Roles.Remove(roleName))
            {
                await userRoleCollection.UpdateOneAsync
                (
                    Builders <ExtenderUser <TUserId> > .Filter.Eq("Id", ((IIdentityUser <TUserId>)user).Id),
                    Builders <ExtenderUser <TUserId> > .Update.Set("Roles", userRoleHolder.Roles),
                    new UpdateOptions { IsUpsert = true }
                );
            }
        }
Example #5
0
        public async Task RemoveClaimAsync(TUser user, Claim claim)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, f => f.Project(u => u.Claims));

            if (extendedUser.Claims.Remove(claim))
            {
                IMongoCollection <ExtenderUser <TUserId> > userCollection = GetCollection <ExtenderUser <TUserId> >(UserCollectionName);

                await userCollection.UpdateOneAsync
                (
                    Builders <ExtenderUser <TUserId> > .Filter.Eq("Id", ((IIdentityUser <TUserId>)user).Id),
                    Builders <ExtenderUser <TUserId> > .Update.Set("Claims", extendedUser.Claims)
                );
            }
        }
        public async Task <int> IncrementAccessFailedCountAsync(TUser user)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, f => f.Project(u => u.AccessFailedCount));

            extendedUser.AccessFailedCount++;

            IMongoCollection <ExtenderUser <TUserId> > userCollection = GetCollection <ExtenderUser <TUserId> >(UserCollectionName);

            await userCollection.UpdateOneAsync
            (
                Builders <ExtenderUser <TUserId> > .Filter.Eq("Id", ((IIdentityUser <TUserId>)user).Id),
                Builders <ExtenderUser <TUserId> > .Update.Set("AccessFailedCount", extendedUser.AccessFailedCount)
            );

            return(extendedUser.AccessFailedCount);
        }
        public async Task AddLoginAsync(TUser user, UserLoginInfo login)
        {
            IMongoCollection <ExtenderUser <TUserId> > userCollection = GetCollection <ExtenderUser <TUserId> >(UserCollectionName);

            ExtenderUser <TUserId> userRoleHolder = await userCollection
                                                    .Find(Builders <ExtenderUser <TUserId> > .Filter.Eq("Id", ((IIdentityUser <TUserId>)user).Id))
                                                    .SingleAsync();

            if (userRoleHolder.Logins.Add(login))
            {
                await userCollection.UpdateOneAsync
                (
                    Builders <ExtenderUser <TUserId> > .Filter.Eq("Id", ((IIdentityUser <TUserId>)user).Id),
                    Builders <ExtenderUser <TUserId> > .Update.Set(holder => holder.Logins, userRoleHolder.Logins),
                    new UpdateOptions { IsUpsert = true }
                );
            }
        }
        public async Task RemoveLoginAsync(TUser user, UserLoginInfo login)
        {
            TUserId userId = ((IIdentityUser <TUserId>)user).Id;

            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync
                                                  (
                userId,
                find =>
            {
                find.Project("Logins");
            }
                                                  );

            if (extendedUser.Logins.Remove(login))
            {
                IMongoCollection <ExtenderUser <TUserId> > userCollection = GetCollection <ExtenderUser <TUserId> >(UserCollectionName);

                await userCollection.UpdateOneAsync
                (
                    Builders <ExtenderUser <TUserId> > .Filter.Eq("Id", userId),
                    Builders <ExtenderUser <TUserId> > .Update.Set("Logins", extendedUser.Logins)
                );
            }
        }
        public async Task <DateTimeOffset> GetLockoutEndDateAsync(TUser user)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, f => f.Project(u => u.LockoutEndDate));

            return(extendedUser.LockoutEndDate);
        }
        public async Task <bool> GetLockoutEnabledAsync(TUser user)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, f => f.Project(u => u.LockoutEnabled));

            return(extendedUser.LockoutEnabled);
        }
        public async Task <int> GetAccessFailedCountAsync(TUser user)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, f => f.Project(u => u.AccessFailedCount));

            return(extendedUser.AccessFailedCount);
        }
        public async Task <bool> GetEmailConfirmedAsync(TUser user)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, p => p.Project(extUser => extUser.EmailConfirmed));

            return(extendedUser.EmailConfirmed);
        }
        public async Task <bool> GetTwoFactorEnabledAsync(TUser user)
        {
            ExtenderUser <TUserId> extendedUser = await FindExtendedUserByIdAsync(((IIdentityUser <TUserId>)user).Id, p => p.Project("TwoFactorAuthenticationEnabled"));

            return(extendedUser.TwoFactorAuthenticationEnabled);
        }