Auto assign roles during registration?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
5/7/2013 4:11:42 PM
Gravatar
Total Posts 62

Auto assign roles during registration?

I see there is a thread about this question, but I was wondering if you already have a code that I could reuse?

http://www.mojoportal.com/Forums/Thread.aspx?pageid=5&t=9370~-1

5/8/2013 11:02:19 AM
Gravatar
Total Posts 18439

Re: Auto assign roles during registration?

Newly created users are added to the role named "Authenticated Users"

Just now I implemented a new web.config setting that will be available after the next release of mojoPortal

<add key="DefaultRolesForNewUsers" value="" />

You will be able to populate that with a semi colon separated string of role names. If those roles exist in the site then new users will be added to them automatically.

However, I must say that I fail to see the benefit of being able to do this since the Authenticated Users role already exists I do not see what using a custom role there would provide any extra value since it is given to all users. If you want to add user to roles based on conditional logic you would have to do it using a custom user registered handler.

A more useful scenario is to grant paid access to a custom role that is used to protect premium content like in Site Membership Pro, and just use the built in "Authenticated Users" role for any content that should be visible to all registered users.

Hope that helps,

Joe

5/8/2013 11:15:09 AM
Gravatar
Total Posts 62

Re: Auto assign roles during registration?

Actually, what I am trying to do is add another field ("Code") in the registration form and so that event handler would check if correct code entered during registration and assign user to that custom group which provides them with automatic access to certain page. I did read your example for User Registered Event handles, but I just want to see if you have code that would assign the user to the group.

5/8/2013 11:27:39 AM
Gravatar
Total Posts 18439

Re: Auto assign roles during registration?

So you would have to add  a custom user profile property required for registration, and then implement a user registered handler that looks up that property and adds the user to a role accordingly.

For almost anything you want to do you can get ideas about how to do it by researching the existing code in mojoPortal. For example see the method AddUserToDefaultRoles in Role.cs for example code for adding the user to roles in the database. Note that after adding a user to a role(s) you would want to set the RolesChanged property to true on the user object and save it. This will make sure the user's role cookie is updated on the next web request by that user.

5/8/2013 1:28:20 PM
Gravatar
Total Posts 62

Re: Auto assign roles during registration?

Excellent, I'll take a look at this!

Also, related to this. Can you tell me if I can change the custom field value stored in Users table instead of UserProperties?

5/8/2013 1:51:35 PM
Gravatar
Total Posts 18439

Re: Auto assign roles during registration?

No, you should not modify any mojoportal tables with custom columns just as you should not modify any mojoPortal code.

Example code of how to retrieve the value is at the bottom of the documentation about user profile properties.

You must sign in to post in the forums. This thread is closed to new posts.