Override the default SignIn view/controller (Users/Account/LogOn) using a custom module???

Topics: Core, Customizing Orchard, Writing modules
Jan 27, 2013 at 11:18 PM

Hi,

Is it possible to override the default SignIn view/controller (Users/Account/LogOn) with a custom module?

On a default Orchard website (core), there is a SignIn link on the bottom of the page, click it then bring you to the /Users/Account/Logon page.

What we try to do is to write a custom module to override this behavior:

1. Instead of go to that default Logon link, it should go to our custom module view say:

/MyModule/Account/Logon ;

2. It should use the custom logon logic instead of the default one.


How can we do that in a custom module?

Thanks!

Jan 28, 2013 at 7:46 PM

Any idea?

Jan 28, 2013 at 8:04 PM

Yes, you can override the templates that link to login/signin so that they render URL's that point to your own custom controller. Define routes for your controller in your module's Routes.cs. 

Jan 29, 2013 at 3:27 PM

Having done this quite extensively (creating some sort of hybrid mess) with one of our module then yes it is possible. But that was mostly done between Orchard 0.9 and 1.1 and kept going with our business logic to the current 1.6 version. Im curious now if I could just replace it completely with something more simple now I know my way around a lot better. 

In its simplest you should be able to create an alternate of the login shape and change the route that is created for the form post. Re-render the login shape if that fails validation or something in the controller. Hmm here we've created our own shape rather than an alternate, maybe that wasn't possible when I created my module (I'll try checking if that is possible again some point) . 

Our main problem to get around was to login with just a email - just a subscription kind of thing, then feeding them passwords only if they needed access to admin areas / restricted areas. Similarly changing the views for when a person registers but without a password etc.

You can change the default un-authorized url in the Orchard.Web Web.config file:

<authentication mode="Forms">
      <forms loginUrl="~/Users/Account/AccessDenied" timeout="2880"/>
 </authentication>

Provide your own route if you like. Our module create a simple one: "~/Login". 99% Ive just kept it as above, as if they are unauthorized they are likely requiring access which doesn't need custom logic, but follow the default one ie to the admin or a section of admin. The rest of the work would be changing links and things in the themes and possibly any profile modules to your login path.

I'm curious of your scenario though. What are you trying to achieve that isn't there with the default login / register views?

Hope that gets you started at least.

Matt