Ejemplo n.º 1
0
        public override IQueryable <UserLink> GetUserLinks()
        {
            List <UserLink> links = new List <UserLink>();
            //This could be slow if there are a lot of potential users.
            int pageIndex = 0;
            List <MembershipUser> users = CobaltWebApi.GetUsers(CobaltWebApi.MAX_NUMBER_OF_RECORDS, pageIndex);

            while (users.Count > 0)
            {
                foreach (MembershipUser user in users)
                {
                    foreach (string role in user.UserGroups.Select(r => r.Name).Union(user.UserRoles.Select(r => r.Name)))
                    {
                        Role     userRole = this.GetRoles().Where(r => r.Name == role).FirstOrDefault();
                        UserLink link     = new UserLink()
                        {
                            ApplicationName = base.ApplicationName, Id = Guid.NewGuid(), Role = userRole, UserId = user.Id
                        };
                        links.Add(link);
                        linkLookup[user.Id.ToString() + userRole.Id.ToString()] = link;
                    }
                }
                pageIndex++;
                users = CobaltWebApi.GetUsers(CobaltWebApi.MAX_NUMBER_OF_RECORDS, pageIndex);
            }
            return(links.AsQueryable());
        }
Ejemplo n.º 2
0
 public override IQueryable <Role> GetRoles()
 {
     return(CobaltWebApi.GetRoles().Select(r => new Role()
     {
         Id = r.Id, ApplicationName = base.ApplicationName, Name = r.Name
     }).AsQueryable());
 }
Ejemplo n.º 3
0
        public override Role GetRole(string roleName)
        {
            MembershipRole role = CobaltWebApi.GetRoles().FirstOrDefault(r => r.Name == roleName);

            return(new Role()
            {
                Id = role.Id, ApplicationName = base.ApplicationName, Name = role.Name
            });
        }
Ejemplo n.º 4
0
        public override bool ValidateUser(Guid userId, string password)
        {
            MembershipUser user = CobaltWebApi.GetUserById(userId);

            if (user != null && !string.IsNullOrEmpty(user.UserName))
            {
                return(this.ValidateUser(user.UserName, password));
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user.
        /// </summary>
        /// <param name="username">The name of the user to get information for.</param>
        /// <param name="userIsOnline">true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the specified user's information from the data source.
        /// </returns>
        public override System.Web.Security.MembershipUser GetUser(string username, bool userIsOnline)
        {
            MembershipUser user = CobaltWebApi.GetUserByUserName(username);

            if (user != null)
            {
                return(this.CreateMembershipUser(user));
            }
            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets information from the data source for a user based on the unique identifier for the membership user. Provides an option to update the last-activity date/time stamp for the user.
        /// </summary>
        /// <param name="providerUserKey">The unique identifier for the membership user to get information for.</param>
        /// <param name="userIsOnline">true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the specified user's information from the data source.
        /// </returns>
        public override System.Web.Security.MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            Guid           id   = (Guid)providerUserKey;
            MembershipUser user = CobaltWebApi.GetUserById(id);

            if (user != null)
            {
                return(this.CreateMembershipUser(user));
            }
            return(null);
        }
Ejemplo n.º 7
0
        public override Role GetRole(Guid id)
        {
            MembershipRole userRole = CobaltWebApi.GetRoleById(id);

            if (userRole != null)
            {
                return(new Role()
                {
                    Id = userRole.Id, ApplicationName = base.ApplicationName, Name = userRole.Name
                });
            }
            return(null);
        }
Ejemplo n.º 8
0
        public override User GetUser(string userName)
        {
            MembershipUser user = CobaltWebApi.GetUserByUserName(userName);

            if (user != null)
            {
                User newUser = new User()
                {
                    Id = user.Id, ApplicationName = base.ApplicationName, IsApproved = true
                };
                newUser.SetUserName(userName);
                return(newUser);
            }
            return(null);
        }
Ejemplo n.º 9
0
        public override IQueryable <Role> GetRolesForUser(Guid userId)
        {
            MembershipUser user  = CobaltWebApi.GetUserById(userId);
            List <Role>    roles = new List <Role>();

            roles.AddRange(user.UserRoles.Select(r => new Role()
            {
                Id = r.Id, ApplicationName = base.ApplicationName, Name = r.Name
            }));
            roles.AddRange(user.UserGroups.Select(r => new Role()
            {
                Id = r.Id, ApplicationName = base.ApplicationName, Name = r.Name
            }));
            return(roles.AsQueryable <Role>());
        }
Ejemplo n.º 10
0
        public override IList <User> GetUsersInRole(Guid roleId)
        {
            //You could loop through to get every users but it's not recommended from a performance standpoint. This will return only the first 5000 records.
            List <MembershipUser> users      = CobaltWebApi.GetUsersInRole(roleId, CobaltWebApi.MAX_NUMBER_OF_RECORDS, 0);
            List <User>           returnList = new List <User>();

            foreach (MembershipUser user in users)
            {
                returnList.Add(new User()
                {
                    Id = user.Id, ApplicationName = base.ApplicationName, IsApproved = true
                });
            }
            return(returnList);
        }
Ejemplo n.º 11
0
        public override IQueryable <User> GetUsers()
        {
            //You could loop through to get every users but it's not recommended from a performance standpoint
            List <MembershipUser> top5000Users = CobaltWebApi.GetUsers(CobaltWebApi.MAX_NUMBER_OF_RECORDS, 0);
            List <User>           newUsers     = new List <User>();

            foreach (MembershipUser user in top5000Users)
            {
                User newUser = new User()
                {
                    Id = user.Id, ApplicationName = base.ApplicationName, IsApproved = true
                };
                newUser.SetUserName(user.UserName);
                newUsers.Add(newUser);
            }
            return(newUsers.AsQueryable());
        }
Ejemplo n.º 12
0
 public override string[] GetRoleNames()
 {
     return(CobaltWebApi.GetRoles().Select(r => r.Name).ToArray());
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Retrieves the membership users.
 /// </summary>
 /// <returns></returns>
 protected virtual MembershipUserCollection RetrieveMembershipUsers()
 {
     return(this.ConvertToMembershipUserCollection(CobaltWebApi.GetUsers(CobaltWebApi.MAX_NUMBER_OF_RECORDS, 0).ToArray()));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Gets a collection of all the users in the data source in pages of data.
 /// </summary>
 /// <param name="pageIndex">The index of the page of results to return. pageIndex is zero-based.</param>
 /// <param name="pageSize">The size of the page of results to return.</param>
 /// <param name="totalRecords">The total number of matched users.</param>
 /// <returns>
 /// A <see cref="T:System.Web.Security.MembershipUserCollection"></see> collection that contains a page of pageSize<see cref="T:System.Web.Security.MembershipUser"></see> objects beginning at the page specified by pageIndex.
 /// </returns>
 public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
 {
     totalRecords = CobaltWebApi.MAX_NUMBER_OF_RECORDS;
     return(this.ConvertToMembershipUserCollection(CobaltWebApi.GetUsers(pageSize, pageIndex).ToArray()));
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Retrieves the membership users.
 /// </summary>
 /// <param name="emailAddress">The email address.</param>
 /// <returns></returns>
 protected virtual MembershipUserCollection RetrieveMembershipUsers(string userName)
 {
     return(this.ConvertToMembershipUserCollection(new MembershipUser[] { CobaltWebApi.GetUserByUserName(userName) }));
 }
Ejemplo n.º 16
0
        public override bool IsUserInRole(Guid userId, string roleName)
        {
            MembershipUser user = CobaltWebApi.GetUserById(userId);

            return(user.UserRoles.Any(r => r.Name == roleName) || user.UserGroups.Any(r => r.Name == roleName));
        }
Ejemplo n.º 17
0
        public override bool IsUserInRole(Guid userId, Guid roleId)
        {
            MembershipUser user = CobaltWebApi.GetUserById(userId);

            return(user.UserRoles.Any(r => r.Id == roleId) || user.UserGroups.Any(r => r.Id == roleId));
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Verifies that the specified user name and password exist in the data source.
 /// </summary>
 /// <param name="username">The name of the user to validate.</param>
 /// <param name="password">The password for the specified user.</param>
 /// <returns>
 /// true if the specified username and password are valid; otherwise, false.
 /// </returns>
 public override bool ValidateUser(string username, string password)
 {
     return(CobaltWebApi.ValidateUser(username, password));
 }
Ejemplo n.º 19
0
 public override bool ValidateUser(User user, string password)
 {
     return(CobaltWebApi.ValidateUser(user.UserName, password));
 }