Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesChange Expiry Date of a Security RoleChange Expiry Date of a Security Role
Previous
 
Next
New Post
12/25/2011 12:21 AM
 

Hello all,

I want to change the "Expiry Date" of a Security Role of an user. How would I update (or change) it in a code-behind file? To further explain the problem, I like to utilize the Security Role feature to control the users' access to a certain module (or page). You can think this as a subscription based access control to a module (or page). I like to update the user's Expiry Date based on a certain condition (or event firing).

I am aware of UserInfo (DNN class) but I cannot find a way to update (or change) the Expiry Date of a particular Security Role. 

Thank you.

Woogon Chung


 
New Post
12/25/2011 6:47 AM
 
Take a look at the DotNetNuke.Security.Roles.RoleController class. As I recall there is a method AddUserRole which creates the UserRole if it does not already exist or updates it with a new EffectiveDate and ExpiryDate if it does. I don't have a DNN source solution open on this computer so can't give you all the details.

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
12/25/2011 6:59 AM
 

Roles in DNN are not a part of UserInfo they are managed separately by the roles controller entity.

For example - to add a user to a new role and set and expiry date of 31 January 2012:

DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();

DotNetNuke.Security.Roles.RoleInfo someRole = rc.GetRoleByName(PortalId, "Some Role");

DateTime expiryDate = new DateTime(2012,1,31)'

rc.AddUserRole(thisPortalId, someuser.UserId, someRole.RoleID, expiryDate  );Ne

Next there is a way to have the system automatically update a role to a new date if the parent role has a billing period defined.

If for example the role Some Role has a period of 1 Month defined in Admin - the following would cause the expiry date of a userinfo someuser to be incremented by a1 Month.

DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();

DotNetNuke.Security.Roles.RoleInfo someRole = rc.GetRoleByName(PortalId, "Some Role"); 

rc.UpdateUserRole(PortalID, someuser.UserId , someRole.RoleID );

Alternatively, if you want to be able to control the exact date the expiry date is updated to without having to rely on the period defined for the role - I tend to perform 2 steps - delete the current role and add a new one.

DotNetNuke.Security.Roles.RoleInfo someRole = rc.GetRoleByName(PortalId, "Some Role");
 
rc.DeleteUserRole(PortalId, someuser.UserId , someRole.RoleID);

DateTime expiryDate = new DateTime(2012,1,31)'

rc.AddUserRole(thisPortalId, someuser.UserId, someRole.RoleID, expiryDate  ); 

NOTE - you can also do this in one step - bu JUST calling the rc.AddUser without calling the rc.DeleteUser - cant recall why we used to do the delete and add - think it was about event reporting.  If you call rc.AddUser and event already exists - it will just update the expiry date.

I would also suggest you wrap the Deleteuser / Adduser calls in try/catch since if the role does not exist or already exists you may get an exception error.

One last thing also - make sure once you finish any role manipulation that you clear the system caches.

DotNetNuke.Security.PortalSecurity.ClearRoles();

DotNetNuke.Common.Utilities.DataCache.ClearUserCache(PortalId, someUser.Username);

Westa

,




 
New Post
12/25/2011 10:18 AM
 

Wow ...

Thank you so much for the all detailed information with Info and Controller Classes. I thought the Roles are under the UserInfo, but learned they are actually the other ways.

Hoping one day that  I will be able to help others, I express my thanks to you all.

Woogon Chung


 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesChange Expiry Date of a Security RoleChange Expiry Date of a Security Role


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out