Content Limited To A User Group - How To Go To Login Instead Of A 404

So this is fairly straightforward. In CS Cart you can limit Pages to certain usergroups. But if someone not logged in tries to access them, it gives a 404 instead of a 'Please log in' page.

I could put a redirect on the 404 page to the login page, but then that would not work well for people with real 404 errors.

Option #1) How can I get the cart to differentiate between an actual 404 vs protected content? There must be a 404 function that knows whether the page is non-existent vs simply protected.

Option #2) I made 2 identical menus, but changed the links. I control which menu shows up by creating my own wrappers that check for their user group using smarty 'if' statements. But the links are problematic. I can pop open a box using a css class, but the targeting of the login box requires a tag that can't be fed into a menu item. Is there any way to pop open the login box from a menu item instead of sending them to the login page?

Option 2 would be smoother in some ways, but Option 1 is probably most realistic. I always thought it was kind of strange that protected pages generated a 404 error, as if they didn't exist.

Report it to bugracker. You shouldn't get a 404 for a group permission issue. You should get a 403 if the user is logged in and is not a member of the group. But if not logged in, it (as you've said) redirect to the login page.

But if you want to do this yourself (untested) you should be able to do something akin to the following. In

app/controllers/frontend/pages.php

find lines that look like

    if (empty($page) || ($page['status'] == 'D' && !$preview)) {
    return array(CONTROLLER_STATUS_NO_PAGE);
}

in the first 'if($mode == 'view')' condition and change them to read:

if (empty($page) || ($page['status'] == 'D' && !$preview)) {
    if(empty($_SESSION['auth']['user_id']) && db_get_field("SELECT page_id FROM ?:pages WHERE page_id=?i && status!=?s", $_REQUEST['page_id'], 'D') ) {
        fn_set_notification('N', __("notice"), "Restricted page, please login", 'K');
        return array(CONTROLLER_STATUS_OK, "auth.login_form");
    }
    return array(CONTROLLER_STATUS_NO_PAGE);
}

}

Updated to add a message. You might want to put it in a language variable if you have multiple langugages.

Hi,

I'm trying to do this, but it does not shows the "LOG IN" page

can you post your actual code (inside code tags)?