Require Login to view catalog

8 years ago
I have put together a site with additional views(pages) What I am needing to do is only allow non-logged in accounts to view just the front pages and not get access to the catalog at all without being signed in.

I am using 2.3 and cannot seem to think of the best way to do this
8 years ago
Hi Scripter,
Did you have any success with this?

I'm new to nopCommerce and MVC so if you have managed to pull this off, a code example would be amazing.

Thanks,
DB
8 years ago
Hi,

I think this is very easy.

Just add this statement in the beginning of the Category Controller:

if (_workContext.CurrentCustomer.IsRegistered())
{
     return View("YourView");
}
8 years ago
Hi c523,  thank you for the response!

I unsuccessfully tried to apply your idea to the categorynavigation.cshtml which appeared to have the potential to hide the category view from a non-registered user.   I realize this is probably not how I was supposed to interpret your suggestion.

When you say at the beginning of the Category Controller, do you mean in the constructors region of the  CategoryController.cs file?

Your idea makes a lot of sense, I'm just not sure where to put it exactly.  

Thanks again for your help.
8 years ago
Try it in the Category controller and not the view I think that is where you need to aply the change not 100% but worth testing...
8 years ago
Hi DB,

The Category Controller is in \Presentation\Nop.Web\Controllers\CatalogController.cs. Place it at the beginning of this action:
public ActionResult Category(int categoryId, CatalogPagingFilteringModel command)
{
   //place the code here..

}
4 months ago
Does it work in Nop 4.20?
If not, can anyone show me how to do it?

Thanks
4 months ago
Yes, It will work for Nop 4.20 as well.
If you want to redirect your customer to login page then use return Challenge();
instead to explicitly mentioning the view.
Here is what you have to do,
4 months ago
FYI, there are some things you can 'hide' using the Access Control List  (uncheck Guests)

Public store. Allow navigation          
Public store. Display Prices          
Public store. Enable shopping cart          
Public store. Enable wishlist
4 months ago
rmahbub63 wrote:
Yes, It will work for Nop 4.20 as well.
If you want to redirect your customer to login page then use return Challenge();
instead to explicitly mentioning the view.
Here is what you have to do,


Thank you so much. Your solution resolved my question!