DNN User Merge for Multiple Portals

By Unknown | Labels: , , , ,


My boss was hounding me about why he had to have multiple usernames for our different DNN portals (we have one for Customer Support, one for Sales and one for Intranet purposes). By default DNN didn't allow me to create users for those portals with identical user names. So after playing with the data a bit I figured out a way and wanted to share it with you and keep it here in case I need to do it again and forget how.

First we need to understand the fundamental underpinnings of the Users structure inside the database. We will be using the Host SQL tab to perform data manipulation so make sure you have the database backed up before attempting these hacks.

So User permissions are basically set in three tables:

  1. Users
  2. UserPortals
  3. UserRoles
These are all important tables to keep consistent. So lets say you have user 'foo' in the Users table, his record would be something like this:

UserIDUsernameFirstNameLastNameIsSuperUserAffiliateIdEmailDisplayNameUpdatePassword
1fooFooBar
foo@bar.comFoo Bar

You could get access to this record to see it in this state by passing the SQL query:

SELECT * FROM Users WHERE Username = 'foo'


So now lets say that you have another portal where foo also needs access and you have set him up another user for that portal called foo2:

UserIDUsernameFirstNameLastNameIsSuperUserAffiliateIdEmailDisplayNameUpdatePassword
1fooFooBar foo@bar.comFoo Bar
2
foo2FooBar foo@bar.comFoo Bar

As you can see these are essentially identical users but DNN will not let you log into portal 1 with user 2 or into portal 2 with user 1. The secret here is UserPortals. First determine what user is assigned to which portal. To do this will use the SQL statement:

SELECT * FROM Users INNER JOIN UserPortals ON Users.UserID = UserPortals.UserID WHERE Email = 'foo@bar.com'


Now notice that since the usernames are not the same, the ticket was to use a field where they match and since email is the usual suspect I decided to use that. The results of that query would look something like this:

UserIDUsernameFirstNameLastNameIsSuperUserAffiliateIdEmailDisplayNameUpdatePasswordUserId1PortalIdUserPortalIdCreatedDateAuthorised
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM
6foo2FooBar foo@bar.comFoo Bar64511/11/2009 9:56:05 PM

Ok so now we know which portals are for which user, next lets also get the roles, because the roles are different for each portal. So we add to the above SQL statement:

SELECT * FROM Users INNER JOIN UserPortals ON Users.UserID = UserPortals.UserID INNER JOIN UserRoles ON Users.UserID = UserRoles.UserID WHERE Email = 'foo@bar.com'


Which yields us:

UserIDUsernameFirstNameLastNameIsSuperUserAffiliateIdEmailDisplayNameUpdatePasswordUserId1PortalIdUserPortalIdCreatedDateAuthorisedUserRoleIDUserID2RoleIDExpiryDateIsTrialUsedEffectiveDate
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM957
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM1058
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM1156
6foo2FooBar foo@bar.comFoo Bar64511/11/2009 9:56:05 PM12610
6foo2FooBar foo@bar.comFoo Bar64511/11/2009 9:56:05 PM13611
6foo2FooBar foo@bar.comFoo Bar64511/11/2009 9:56:05 PM1469

Ok so there is a lot going on now. Clearly these users are both administrators of their respective sites, now we just need to trim it down to one user, we will use UserID 5 since that is 'foo'. The SQL statement for this would be:

UPDATE UserPortals SET UserID = 5 WHERE UserID = 6;
UPDATE UserRoles Set UserID = 5 WHERE UserID = 6;
DELETE FROM Users WHERE UserID = 6;
SELECT * FROM Users INNER JOIN UserPortals ON Users.UserID = UserPortals.UserID INNER JOIN UserRoles ON Users.UserID = UserRoles.UserID WHERE Email = 'foo@bar.com'


This yields us the following result:

UserIDUsernameFirstNameLastNameIsSuperUserAffiliateIdEmailDisplayNameUpdatePasswordUserId1PortalIdUserPortalIdCreatedDateAuthorisedUserRoleIDUserID2RoleIDExpiryDateIsTrialUsedEffectiveDate
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM957
5fooFooBar foo@bar.comFoo Bar54511/11/2009 9:56:05 PM957
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM1058
5fooFooBar foo@bar.comFoo Bar54511/11/2009 9:56:05 PM1058
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM1156
5fooFooBar foo@bar.comFoo Bar54511/11/2009 9:56:05 PM1156
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM12510
5fooFooBar foo@bar.comFoo Bar54511/11/2009 9:56:05 PM12510
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM13511
5fooFooBar foo@bar.comFoo Bar54511/11/2009 9:56:05 PM13511
5fooFooBar foo@bar.comFoo Bar53411/11/2009 9:54:51 PM1459
5fooFooBar foo@bar.comFoo Bar54511/11/2009 9:56:05 PM1459

as you can see, user foo2 has been deleted entirely and if you log into either site with foo you will have the permissions of foo and foo2 from before the hack.

Hope this helps some people out there make sense of their DNN user issues.

0 comments:

Post a Comment