This project is read-only.

How to extend default users implementation?

Nov 27, 2010 at 6:16 PM
Edited Nov 27, 2010 at 6:16 PM

Hi, I've been working on Orchard modules for some time and I'm currently struggling with extending the default implementation of users/login.

1. I have a custom module for handling user login and don't want to let users login locally through /Users/Account/LogOn. As far as I have seen there is no possibility to disable user login (maybe Orchard.Users settings entry should have such field?), or I'm just missing something?

2. If the former is impossible, maybe we can somehow hide links to LogOn page? Link to login page is always rendered as a part of a default theme and I wonder if there's a possibility to replace it with my custom link (eg. creating a shape in my module which overrides default)? It leaves LogOn page accessible via URL, but I can live with that...

3. I know that Orchard.Users is a core module, but maybe I can disable it and fully replace it with my custom module (with different implementation of IMembershipService, UserParts and so on). Isn't it going to corrupt the whole app?

4. And last question (like 2., but in general): Is there a simple way to override default rendering of elements on the page? Is it enough to place eg. User.cshtml under Views folder of my module to override rendering of New.User() in theme's Layout.cshtml? Do I need more steps to make it work, or does Orchard do the whole replacement automagically?:)




Nov 28, 2010 at 11:03 AM

Answering my own question:

4. Yes, it's enough to place corresponding view, eg. User.cshtml under Views folder to override default rendering. But the question is - if I have more than one custom module overriding the same view - how can I determine which view will be rendered (or - which module has top priority)?

Nov 28, 2010 at 11:47 AM

4. I was wrong. Placing view with the same name just made both not render, I think... I placed an empty User.cshtml under my module Views folder and thought it was it, but no - even after deletion, the User.cshtml from core shapes is still not rendering...:/ Any clues?

Nov 28, 2010 at 3:42 PM

4. As explained here:

It should be \Views\Items\Content-{ContentTypeName}.cshtml

Note that, in the specific case of User, there is only an editor view named: "Content-User.Edit.cshtml", you can open it in the Orchard.Users module.
That's what you see when you open http://.../Admin/Users/Edit/2

Pierre Henri.

Nov 28, 2010 at 3:54 PM


Thanks, but I think my case is a bit different.

You are referring to overriding Item templates and this is totally correct, but User.cshtml shape is only displaying logon links and is not connected in any way with Orchard.Users.

My intention is not to override shapes defined in Orchard.Users, but in Orchard.Core/Shapes/Views/User.cshtml, which is a default shape for rendering user links (called as New.User() from Layout.cshtml in TheThemeMachine theme). I successfully managed to override the default by placing my own User.cshtml file under /Views folder in my module, but the problem is when currently used theme also does the same thing... In this case, Orchard uses the User.cshtml file defined in theme and not in module.



Nov 28, 2010 at 7:29 PM

Right, modules don't override shape rendering, they only define the original that can then be overridden by themes. I think what you have to do here is to hook into shape factory events.