Skip to content

Instantly share code, notes, and snippets.

@valadas
Created January 5, 2023 18:51
Show Gist options
  • Select an option

  • Save valadas/6582ef43aeeabe0d728e57831547b69b to your computer and use it in GitHub Desktop.

Select an option

Save valadas/6582ef43aeeabe0d728e57831547b69b to your computer and use it in GitHub Desktop.
Maps all DNN Users to a portal
DECLARE @UserId int
DECLARE @PortalId int
SET @PortalId = 6 -- <<<< Adjust to your portal ID
DECLARE @Authorized bit
SET @Authorized = 0 -- <<<< Adjust if you want the users to be authorized or not
DECLARE MY_CURSOR CURSOR
LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR
SELECT DISTINCT UserID
FROM Users
OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @UserId
WHILE @@FETCH_STATUS = 0
BEGIN
-- Map user to portal
IF not exists ( SELECT 1 FROM dbo.UserPortals WHERE UserID = @UserID AND PortalID = @PortalID ) AND @PortalID > -1
BEGIN
INSERT INTO dbo.UserPortals (
UserID,
PortalID,
Authorised,
CreatedDate
)
VALUES (
@UserID,
@PortalID,
@Authorized,
getdate()
)
END
-- End Map user to portal
PRINT @UserId
FETCH NEXT FROM MY_CURSOR INTO @UserId
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment