예제 #1
0
        private List <int> GetUserIdsFromNames(IDatabase db, string[] usernames)
        {
            List <int> userIds = new List <int>(usernames.Length);

            foreach (string username in usernames)
            {
                int id = SimpleMembershipProvider.GetUserId(
                    db,
                    SafeUserTableName,
                    SafeUserNameColumn,
                    SafeUserIdColumn,
                    CasingBehavior,
                    username
                    );
                if (id == -1)
                {
                    throw new InvalidOperationException(
                              String.Format(
                                  CultureInfo.CurrentCulture,
                                  WebDataResources.Security_NoUserFound,
                                  username
                                  )
                              );
                }
                userIds.Add(id);
            }
            return(userIds);
        }
예제 #2
0
        // Inherited from RoleProvider ==> Forwarded to previous provider if this provider hasn't been initialized
        public override string[] GetRolesForUser(string username)
        {
            if (!InitializeCalled)
            {
                return(PreviousProvider.GetRolesForUser(username));
            }
            using (var db = ConnectToDatabase()) {
                int userId = SimpleMembershipProvider.GetUserId(db, SafeUserTableName, SafeUserNameColumn, SafeUserIdColumn, username);
                if (userId == -1)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, WebDataResources.Security_NoUserFound, username));
                }

                string query = @"SELECT r.RoleName FROM " + UsersInRoleTableName + " u, " + RoleTableName + " r Where (u.UserId = @0 and u.RoleId = r.RoleId) GROUP BY RoleName";
                return(db.Query(query, new object[] { userId }).Select <dynamic, string>(d => (string)d[0]).ToArray());
            }
        }