3

How to disable front-end login component in Joomla 3?

I have managed to disable front-end user registration by disallowing registration as below.

enter image description here

But still the login form is accessible via below url

index.php?option=com_users&view=login

How can I disable front-end login component without editing the core files?

Given that I have gone through below. I don't want to use a RewriteRule to get it done. I want to show a msg to user that it's disabled.

joomla 3 - how to disable front end login component?

Community
  • 1
  • 1
Techie
  • 44,706
  • 42
  • 157
  • 243

4 Answers4

1

Try this,

Joomla default login module is protected. So you can't edit/disable it from admin side.

Just check extensions-> extension manager -> Search for login

Then that module will display. but you can't make it disable. So the solution for override this feature without touching core files is template override.

You can simply override this view index.php?option=com_users&view=login in your template.

Editing Protected extension via DB tables

The extensions can not be edited, but you can manage it by turning it ON, or OFF. Protected, mean that this extension can not be managed, otherwise it will broke structure of your site. However, if you wish to bring extension to unlocked status, you can access your DB (in my case MySQL edited by phpMyAdmin), find reliable table of structure, find desired string, and change "Status" from "1" to "0". Usually your host providing you with some DB administering tools.

Hope it helps..

Jobin
  • 8,238
  • 1
  • 33
  • 52
1

I wrote a plugin for that. It completely disables 'Users' at the front-end. You could also disable a specific view only for these:

index.php?option=com_users&view=login
index.php?option=com_users&view=registration
index.php?option=com_users&view=profile&layout=edit

This is the code for completely disable users at the front-end

<?php defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;

class PlgSystemCobizDisableLogin extends CMSPlugin
{   
    public function onAfterInitialise()
    {   
        $this->disableLogin();
    }
    
    protected function disableLogin()
    {
        $app = Factory::getApplication();
        if ($app->isClient('site') === false) return;

        $disable_users = $this->params->get('disable_users', 1);
        if (!$disable_users) return;

        $option  = $app->input->getCmd('option');       
        if ($option == 'com_users') {           
            $this->redirect();        
        }
    }
    
    protected function redirect()
    {
        $Itemid = $this->getHomePageItemid();
        $app = Factory::getApplication();
        $link = Route::_('index.php?Itemid=' . $Itemid);
        Factory::getApplication()->enqueueMessage('Toegang gewijgerd', 'error');
        $app->redirect($link);      
    }
    
    protected function getHomePageItemid()
    {
        $tableName = '#__menu';
        $db = Factory::getDbo();
        $query = $db->getQuery(true);
        $query->select('id');
        $query->from($db->quoteName($tableName));
        $query->where($db->quoteName('published') . ' = ' . $db->quote(1));
        $query->where($db->quoteName('home') . ' = ' . $db->quote(1));
        $db->setQuery($query);
        $data = $db->loadResult();
        return $data;
    }
}

Or am I overlooking something here? I acknowledge this disables also registration for users on the front-end. But in most cases that's what I want as well! :-)

  • Indeed you overlooked `/component/users/` as possible address. I edited your post. Also I'm using your code, I hope that's okay. ;-) – alve89 Oct 28 '21 at 12:19
0

in joomla 3.x a simple way i have found is to edit /components/com-users/controller.php and mark view string login like that. i got 404 server response but thats what i wanted. since this is not a url but a component view it is abit hard to redirect.

// Set the default view name and format from the Request.

    // $vName   = $this->input->getCmd('view', 'login');
     $vFormat = $document->getType();
0

If you want to avoid the 404 server response, after editing /components/com-users/controller.php as indicated in the previous comment, you can create a redirection to send from the frontend login page to wherever you want, say the homepage. It does work.