Created
January 5, 2023 18:51
-
-
Save valadas/6582ef43aeeabe0d728e57831547b69b to your computer and use it in GitHub Desktop.
Maps all DNN Users to a portal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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