1 (edited by Simplton 2017-04-09 21:08:47)

Topic: User list for logged-in users only

Greetings All,

I have updated the code below incorporating "sergeyterr's" suggestions, and added email as well:

I was able to find and edit the index.view.php file located in:  root/plugins/box/users/views/frontend/
A simple fix prevents Non-logged in individuals from seeing the list of users -- substitute the below code or adapt as needed.

<table>
    <tr>
        <td></td>
    </tr>
    <?php 

      if (Session::get('user_id')) { // you must be logged in

    foreach ($users as $user) { ?>
    <tr>
        <td style="padding:0 20px 0 0;">
            <a href="<?php echo Site::url(); ?>/users/<?php echo $user['id']; ?>">
            <?php echo $user['login']; ?></a></td>
            <td>
            <?php if ($user['email'] !== '') { ?><b>
            <?php echo __('Email', 'users'); ?></b>:<?php echo  
            Html::email(Html::toText($user['email'])); ?><?php } ?>
        </td>
    </tr>
    <?php }
     } else {
         echo "You must be logged in to view this page!" . Html::nbsp(2);  ?>
         
         <a href="<?php echo Site::url(); ?>/users/login"><?php echo __('Log In', 'users'); ?></a>

<?php } ?>
      
</table>

To stop the "Users" link from showing on the main menu, you can goto:  plugins/box/menu/views/frontend/index.view.php  and replace line 46-ish with:

replace this -->  echo '<li'.$li_active.'>'.'<a href="'.$link.'"'.$anchor_active.$target.'>'.$item['name'].'</a>'.'</li>';

with this:


        if ($item['name']!=='Users') {
               echo '<li'.$li_active.'>'.'<a href="'.$link.'"'.$anchor_active.$target.'>'.$item['name'].'</a>'.'</li>';

        } elseif (Session::get('user_id'))  {
               echo '<li'.$li_active.'>'.'<a href="'.$link.'"'.$anchor_active.$target.'>'.$item['name'].'</a>'.'</li>';

        } else { }

Re: User list for logged-in users only

<table>
    <tr>
        <td></td>
    </tr>
    <?php 

    if ( if (Session::get('user_id')) ) { // you must be logged in

    foreach ($users as $user) { ?>
    <tr>
        <td>
            <a href="<?php echo Site::url(); ?>/users/<?php echo $user['id']; ?>"><?php echo $user['login']; ?></a>
        </td>
    </tr>
    <?php }
     } else {
              echo "You must be logged in to view this page!" . Html::nbsp(2); 
?>
             <a href="<?php echo Site::url(); ?>/users/login"><?php echo __('Log In', 'users'); ?></a>
<?php
     }
      ?>
</table>

Re: User list for logged-in users only

It would be better if there was an opportunity to switch off the user listing completely. Even if the menu entry does not exist, the user profiles can still be shown to anyone, just by typing /users after the URL. And because the emails are shown, this could be a rich source for spammers. The email addresses are masked in the source code, but nevertheless Emails of users should never be shown to the public.

Re: User list for logged-in users only

Torsten-K wrote:

It would be better if there was an opportunity to switch off the user listing completely. Even if the menu entry does not exist, the user profiles can still be shown to anyone, just by typing /users after the URL. And because the emails are shown, this could be a rich source for spammers. The email addresses are masked in the source code, but nevertheless Emails of users should never be shown to the public.

@Hi Torsten-K
go plugins/box/users/views/frontend/profile.view.php

line 6 remove <?php if ($user['email'] !== '') { ?><tr><td><b><?php echo __('Email', 'users'); ?></b>:</td><td><?php echo Html::email(Html::toText($user['email'])); ?></td></tr><?php } ?>
wink

Here you will find templates for monstra and morfy xxwebplus
Best cms

Re: User list for logged-in users only

Thank you, xxwebplus, that did the trick!