Camen Design Forum

How to display more menu for logged in user?

append delete dummy

Hi can some one advice, How to display more menu for logged in user?

I want to add more functionality to NNF forum like data in table.

Maybe @Kroc and @Martijn can explain more details.

Reply RSS

Replies

append delete #1. Martijn

NoNonsense Forum does not really have logged in users. This might make adding additional functionality hard. Note however that this is a conscious decision. When NNF launched [1] this was mentioned:

I don’t want to go through registration and _[…]_ logging in each time.

In fact, this was already an explicitly stated goal of a forum 2 years for the NNF blog post was published on Kroc’s site. Under a section No session, no login, no registration, he writes:

You never have to log in through a dedicated login page beforehand every time, and there’s no session and no cookies so the forum never has to bother you about logging in to post.

So when logged in users are not a thing in the software, that would have to be where you start: build a system for letting users log in. Though if some sort of members-only section is a need for your project, your project might just be too big for NoNonsense Forum to be an effective solution.

All that said, there is a place where NoNonsense Forum sort of simulates the existence of logged in users. The little sign in link in the footer of this very page. When you click it, your web browser will ask you for your username and password. (Important: your browser asks you, not the website!) When you enter your login there, your browser will send it to every page every time.

This is as if you are logging in over and over again, and is how the forum can offer a sign in link without doing any cookies or session handling itself.

You *might* be able to use this logic to show different content to people logged in with this link than to others. Currently the forum is already doing that, see for example lines 278 through 282 of index.php: https://github.com/Kroc/NoNonsenseForum/blob/e8a996c6cd3eb97c9de8762e3aa31b3b29508f93/index.php#L277-L282

Using the theming system, you should be able to add an extra menu to the forum and then add a little bit of DOM templating [3] to your theme’s theme.php file where you use the `AUTH_HTTP` constant in the same way as the forum is doing in index.php.

That should work. Not sure if it will be super clear for your users though, and it is taking a step away from the goals of the forum.

---

[1]: NoNonsense Forum, 1. Features: https://camendesign.com/nononsense_forum#features
[2]: Camen Design: Now With Added Forums, 2. Goals: https://camendesign.com/forums#goals
[3]: Making the Ugly Elegant: Templating With DOM: https://camendesign.com/dom_templating

append delete #2. dummy

All that said, there is a place where NoNonsense Forum sort of simulates the existence of logged in users. The little sign in link in the footer of this very page. When you click it, your web browser will ask you for your username and password. (Important: your browser asks you, not the website!) When you enter your login there, your browser will send it to every page every time.

Understood, so now I manage to add the menu for Sign-in user. in themes/greyscale/index.html.

and add the new menu ID

//is the user already signed-in?
))->remove (AUTH_HTTP
//don’t need the usual name / password fields and the deafult message for anonymous users
? '#nnf_name, #nnf_pass, #nnf_email, #nnf_error-none'
//user is not signed in, remove the "you are signed in as:" field and the message for signed in users
: '#nnf_name-http, #nnf_error-none-http , #new_menu '

So, is it correct ?

Using the theming system, you should be able to add an extra menu to the forum and then add a little bit of DOM templating [3] to your theme’s theme.php file where you use the `AUTH_HTTP` constant in the same way as the forum is doing in index.php.

I will take deeper on DOM templating.

append delete #3. Kroc

Thanks for the description @Martijn; NNF tries to avoid sessions and cookies and storing this kind of infinite-growth data on the server. The sign-in link uses HTTP_AUTH, a feature provided by browsers to prepend the username/password to every request. There is no way to sign-out however other than closing the browser or clearing the cache! The browser is managing this, I have no control over it!

Once signed in however, every request has the username/password included, so you can easily identify the user the same as if they used the user/pw field. The constant AUTH is set to true if the user has provided a correct un/pw and additionally AUTH_HTTP is set to true if they are 'signed in'.

DOMTemplate works on *removing* elements from the template that aren't needed. Therefore, if you want to add a menu for logged-in users, just add the menu HTML to the template file (/themes/greyscale/*.html) and remove the element if the user is not logged in.

You're correct that you just need to add your menu's ID to that list of element-IDs that get removed from the page if the user is *not* signed in :)

:: @Kroc added on 08 Aug ’23 · 09:01

Correction! There appears to be a bug there maybe because that entire chain of DOMTemplate commands is predicated by CAN_POST, a set of conditions based on factors other than signed in status

% php
if (CAN_POST) $template->set (array ( 
    ....
//is the user already signed-in?
))->remove (AUTH_HTTP
%

Therefore you probably want to add your own DOMTemplate call just for your menu, like this:

% php
if (!HTTP_AUTH) $template->remove ( '#menu-id' );
%

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn