User registration / additional information

Topics: Customizing Orchard, General, Writing modules
May 21, 2011 at 12:26 AM

Hi there,

I'm very new to Orchard but not to asp.net MVC.

I need the user to submit additional information when registering to the site. For example, favorite color, etc... Normally I would store this information in a separate table and link the record with the asp.net userID.

Do I need to create a custom module for this?

I just want to double check that there is no out of the box solution for this, before coding something myself!

Thank you!

Coordinator
May 21, 2011 at 12:32 AM

There are a few user profile modules on the gallery that you might want to try.

May 23, 2011 at 10:47 PM

Made some progress.
I am using the Profile module.
It allows me to extend the 'User' ContentType with additional Parts.

I created a module in which I define a custom Part with the required additional Profile information. 
This is working properly. If for example I add this part to the 'Page' content type I can see/edit my custom Part.
Also if I visit myhost/profile/admin I see my custom part information. (this comes from the profile module).

However, on the Register page only the standard fields are shown.
What I need though is that my custom information must also be filled out when registering on the site.

I am slowly becoming familiar with Orchard but I am the dark regarding how to achieve this?

Any help is greatly appreciated!

thx!

May 24, 2011 at 2:14 PM

I needed something similar for a site I'm building. Unfortunately the Profile module doesn't affect the registration page, and due to various implementation details of registration it'd be hard to achieve this. So the easy thing to do is probably just to direct users to the profile page immediately after they've registered.

Actually it's a good idea to keep registration pages as slim as possible, and make more the advanced profile optional anyway. Complex registration forms can seriously put users off!

May 24, 2011 at 4:43 PM

thx for the info randompete!

In this case it is a requirement to have potential users fill out an extended registration form. The site I am working on is for a medical group and members must meet certain criteria.

I am thinking that the best approach is that I create my own registration page. Here I would register the user using the membership API's.

I have less than 5 days experience with Orchard and could really benefit from exchanging ideas with someone more experienced. If possible maybe we can Skype once so you can help me validate some ideas? If you give me a hand, you'll have a place to stay in Ecuador!

 

May 25, 2011 at 3:36 AM

I had to create a custom registration page. It took me about two days but it works. I can probably help you if you need some more info.

May 27, 2011 at 7:18 AM

I'd like to do the same, along with accepting 'terms and conditions' and being able to force a user to accept them again whenever they are updated by an admin.

In the main, I'd like to have a core set of mandatory 'sign up' information on the registration page, and then re-direct them to their profile page where they could fill out the optional profile stuff.

Let me know if you come up with anything, I'd love to know how you did it!

May 27, 2011 at 5:25 PM
Edited May 27, 2011 at 6:05 PM

@GadgetGeek,
randompete was kind enough to give me some valuable advice.
You basically need to define your own module. There you can provide your own registration functionallity.
He recommended to use: OrchardSuppressDependency to override the default controller action in the Orchard.Users module
Here is a thread which explains how to use: http://orchard.codeplex.com/discussions/258197

I have been busy with some other work, I have not started with that yet.
I hope I can get started with it today though.

Let me know how it goes, as we both will be fighting the same battle.
 
** EDIT **

I forgot to mention Pete suggested to derive my controller from the Account controller. 

May 27, 2011 at 10:11 PM

I found some time to work on this today and have got the custom registration code page working.
This is what I ended up doing:

  • Create a module and define a new AccountController (name could be anything you want) with the Register actions.
  • At first, as suggested by Pete, I derived my controller from the standard built in AccountController. However this led to a System.Reflection.AmbiguousMatchException when invoking the URL (because both classes have a Register method).  I guess I could have gone with composition, instead of inheritance. I did not try that though, because I decided to just register the route for that one specific action. In my case that is all I needed. So I added registered a route that applies for Users/Account/Register. What is nice is that the standard AccountController then continues to handle all other actions (LogOn,etc...). 

 Here is the route code:

        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] {
                
                new RouteDescriptor {
                    Priority = 9, // give it a high priority so it overrides standard route
                    Route = new Route(
                        "Users/Account/Register",
                        new RouteValueDictionary {
                            {"area", "Aioi"},
                            {"controller", "Account"},
                            {"action", "Register"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "Aioi"}
                        },
                        new MvcRouteHandler())
                }
            };
        }
I did not end up using the OrchardSuppressDependency either.

Well, hope this helps! 

May 28, 2011 at 2:57 PM

Hi randompete!

I kindly ask you to provide example codes for the method that santiagoIT mentioned about in above posts:

(He recommended to use: OrchardSuppressDependency to override the default controller action in the Orchard.Users module)

I think that will enlighten many people struggling with register function customization like me.

Thank you very much!

May 28, 2011 at 3:28 PM

OrchardSuppressDependency is just an attribute that you can put on any class in your module. As an example:

[OrchardSuppressDependency("Orchard.Core.Users.Controllers.AccountController")]
public class MyAccountController : Orchard.Core.Users.Controllers.AccountController {

  // ...

}

So it's a way to swap a default implementation with one of your own.

Santiago is working on a registration page customization that renders an Edit shape for the User (see http://orchard.codeplex.com/discussions/259327) - so that could be a path to getting a registration page that will build itself based on any parts on the User object (which would be incredibly useful!)