The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Allowing only users to access pages [javascript]

3 posters

Go down

Solved Allowing only users to access pages [javascript]

Post by levy April 24th 2023, 4:19 pm

Greetings everyone and thank you for helping me out!

I'm trying to create some modules for my website and I need some help if you guys could. I haven't been around forumotion for a long time and some of the data process I don't remember.

I'd like to create a HTML page (doesn't really matter but for the description) where only Users can access it in contradiction, if u a guest to show a message. In the HTML format for the templates it was this code but if I try to add it on a HTML page it doesn't work since it doesn't take the comments outside. Could you help me to understand how it's done? Thank you and if it's not possible no worries, we just move along

Code:
<!-- BEGIN switch_user_logged_in -->
            <!-- END switch_user_logged_in -->


            <!-- BEGIN switch_user_logged_out -->
            <!-- END switch_user_logged_out -->


Last edited by levy on April 25th 2023, 4:29 pm; edited 1 time in total
levy
levy
Hyperactive

Male Posts : 2631
Reputation : 350
Language : English, Romanian
Location : Romania

https://portofolio.goodforum.net/

Back to top Go down

Solved Re: Allowing only users to access pages [javascript]

Post by skouliki April 24th 2023, 6:06 pm

skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Allowing only users to access pages [javascript]

Post by levy April 24th 2023, 7:31 pm

Greetings, thank you for the help

Unfortunetly, that's not what I'm looking for. Mainly I'm looking for the data that would allow me to make a difference between somebody being connected to the forum and a guest like the code that i showed up. That comment allows the difference
levy
levy
Hyperactive

Male Posts : 2631
Reputation : 350
Language : English, Romanian
Location : Romania

https://portofolio.goodforum.net/

levy likes this post

Back to top Go down

Solved Re: Allowing only users to access pages [javascript]

Post by Razor12345 April 24th 2023, 8:36 pm

Good evening!

This is a very bad way of blocking content for guests. Such blocking is best implemented on the server side of the website, to which we do not have access.

In our case, if we set a block like this (Example on my test forum), the guests will still have access to the content if they have some knowledge in this subject.

Allowing only users to access pages [javascript] Scree118

I can still view the contents of the page. I can even disable the code that blocks the display of content:

Allowing only users to access pages [javascript] Scree119

The problem is that the data has already come from the server - we can only hide it. And that's not good content protection.

About that:

Code:
<!-- BEGIN switch_user_logged_in -->
            <!-- END switch_user_logged_in -->
 
 
            <!-- BEGIN switch_user_logged_out -->
            <!-- END switch_user_logged_out -->

These are simply comments to the code - nothing more.
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

levy likes this post

Back to top Go down

Solved Re: Allowing only users to access pages [javascript]

Post by levy April 24th 2023, 11:09 pm

Thank you both but it's nothing needed to be too safe let's say since I just don't want to allow them to view pages. The thing that is going on is that I'm using the header and footer of the html page which will take in consideration if you are connected or disconnected. That's why I was thinking to work it like that because it automatically knows if you are connected or not.

The other thing is no, the Comments are not just comments, they take in consideration what's in between them to know what to pick, whether you are connected or not and that's exactly what i need as well. They are in templates, that one mainly is on the overall_header

To have a script that knows when the user is connected or disconnected because if you let's say go to the /h1-test of the forum you'd still see the entire content even if you are connected or not and the code above doesn't work outside the Templates themselves

Here's the Default one

Code:
            <!-- BEGIN switch_user_logged_in -->
            <div id="userlinks" class="clearfix">
               <ul>
                  <li><a href="{U_SEARCH_NEW}">{L_SEARCH_NEW}</a></li>
                  <li><a href="{U_SEARCH_SELF}">{L_SEARCH_SELF}</a></li>
                  <li class="last"><a href="{U_SEARCH_UNANSWERED}">{L_SEARCH_UNANSWERED}</a></li>
               </ul>
               <p>{LOGGED_AS}.</p>
            </div>
            <!-- END switch_user_logged_in -->
            <!-- BEGIN switch_user_logged_out -->
            <div id="userlinks" class="not-connected clearfix">
               <span class="guest">{L_NOT_CONNECTED}</span> <span>{L_LOGIN_REGISTER}</span>
            </div>

Before you mention the {L_NOT_CONNECTED} it's the login_not connected which display only the /login page which is displayed because of the comments above.. As example, please take a look at something old example that I did back in the day or you can try editing them yourself. You'll notice that anything that you display between them will take in consideration if u log in or out

levy
levy
Hyperactive

Male Posts : 2631
Reputation : 350
Language : English, Romanian
Location : Romania

https://portofolio.goodforum.net/

Back to top Go down

Solved Re: Allowing only users to access pages [javascript]

Post by Razor12345 April 25th 2023, 10:53 am

The thing that is going on is that I'm using the header and footer of the html page which will take in consideration if you are connected or disconnected. That's why I was thinking to work it like that because it automatically knows if you are connected or not.

Unfortunately, this does not mean that the page automatically knows it is being viewed by a guest or user. It is purely a question of the design of the HTML page - nothing more.
As a bonus, you add some functionality to your HTML page, which is available on the forum page.
But the list of functionalities does not include identifying the user as a guest or registered user.
The server checks the status of the visitor (guest or registered user). Based on the results of this check, the server sends us the necessary data.
In HTML pages this check is not performed and the server by default sends all the data contained in the file.

The other thing is no, the Comments are not just comments, they take into consideration what's in between them to know what to pick, whether you are connected or not and that's exactly what I need as well. They are in templates, that one mainly is on the overall_header

In the first post, you simply provided comment tags. That's why I gave you this answer in the previous post. Now you provide the full code.
Note that forum variables do not work on HTML pages.

The second code you have indicated consists almost entirely of variables - so it doesn't work on HTML pages.
Because of this, the content blocking logic needs to be written manually.

I've written a little code - if it suits you, we can improve it. In it, I check the navigation menu tabs that are available to us as we use the forum header and footer. If there is a tab with a /login link - I block content that is intended for registered users. If there is no tab - I block the content that is intended for guests.

Code:
<meta charset="UTF-8" />    <meta content="IE=edge" http-equiv="X-UA-Compatible" />    <meta content="width=device-width, initial-scale=1.0" name="viewport" />    <title>Our restaurant</title>    <link href="style.css" rel="stylesheet" />  <style>

.users {
background-color: green;
border: 3px solid green;
display: none;
}

.guests {
display:none;
background-color: blue;
border: 3px solid blue;
}

</style>           
<div class="guests">
          
   <h1>
                <span class="text__guest">Hello, guest! You need to register or log in to see this page.</span>       
   </h1>
</div>
<div class="users">
          
   <h1>
                <span class="text__user">Hello, user!You see this page because you are authorised</span>       
   </h1>
</div>
          <script>
      window.addEventListener('load', function() {
         
          let loggin = document.querySelectorAll('a.mainmenu');
          for (let i = 0; i <= loggin.length; i++) {
            if (loggin[i].href === 'https://testtesttest.forumotion.me/login') {
document.querySelector('.guests').style.display = 'block';
document.querySelector('.users').style.display = 'none';
} else {
document.querySelector('.guests').style.display = 'none';
document.querySelector('.users').style.display = 'block';
}
          }
          });
    </script>

Result:

Registered users

Allowing only users to access pages [javascript] Scree121

Guests

Allowing only users to access pages [javascript] Scree120

Living example: https://testtesttest.forumotion.me/h5-11111111111111111111

If the login button is always the last one, this will significantly reduce checking time, as we will only be checking one particular tab in the navigation menu.
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1586
Reputation : 268
Language : Ukr, Rus, Eng
Location : Ukraine

TonnyKamper likes this post

Back to top Go down

Solved Re: Allowing only users to access pages [javascript]

Post by levy April 25th 2023, 4:29 pm

Thank you so much, that's pretty much what I was in need for.
levy
levy
Hyperactive

Male Posts : 2631
Reputation : 350
Language : English, Romanian
Location : Romania

https://portofolio.goodforum.net/

Back to top Go down

Solved Re: Allowing only users to access pages [javascript]

Post by skouliki April 25th 2023, 7:06 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules
skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum