Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d0eca99
mod_login converted to service provider
joomlaweby Jan 6, 2025
5c83556
mod_login docblock updated
joomlaweby Jan 6, 2025
ea04b14
injected application in LoginHelper in mod_login
joomlaweby Feb 4, 2025
e6bd00e
deprecated getType function fixed
joomlaweby Feb 4, 2025
56b8449
fix in docblock
joomlaweby Feb 8, 2025
2cf5b58
Merge branch '5.4-dev' of https://github.com/joomla/joomla-cms into m…
joomlaweby Jun 29, 2025
73bea6d
getModuleType to getLayoutType
joomlaweby Jun 29, 2025
e24509a
template file rollback
joomlaweby Jun 29, 2025
0126002
getLayoutType refactored to getMenuItemType
joomlaweby Jun 30, 2025
2ffce64
injected User object
joomlaweby Jun 30, 2025
1330167
remove injected application from getMenuItemType
joomlaweby Jun 30, 2025
6962317
getMenuItemType refactored to getReturnType
joomlaweby Jun 30, 2025
2a9dc11
Merge branch '5.4-dev' of https://github.com/joomla/joomla-cms into m…
joomlaweby Aug 3, 2025
254e64a
dispatch method for mod_login
joomlaweby Aug 4, 2025
aab4f30
methods order in LoginHelper
joomlaweby Aug 4, 2025
51a6df0
return types in LoginHelper
joomlaweby Aug 4, 2025
4b64e18
getUserType instead of getReturnType
joomlaweby Aug 4, 2025
a9d3b12
docblock fixed
joomlaweby Aug 4, 2025
eb920c5
Merge branch '5.4-dev' into mod_login
muhme Aug 5, 2025
3017451
empty line removed
joomlaweby Aug 5, 2025
1f6e78f
Merge branch '5.4-dev' of https://github.com/joomla/joomla-cms into m…
joomlaweby Aug 5, 2025
ba61935
Merge branch 'mod_login' of github.com:joomlaweby/joomla-cms into mod…
joomlaweby Aug 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions modules/mod_login/mod_login.php

This file was deleted.

2 changes: 1 addition & 1 deletion modules/mod_login/mod_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description>MOD_LOGIN_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Module\Login</namespace>
<files>
<filename module="mod_login">mod_login.php</filename>
<folder module="mod_login">services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
Expand Down
41 changes: 41 additions & 0 deletions modules/mod_login/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @package Joomla.Site
* @subpackage mod_login
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\Service\Provider\HelperFactory;
use Joomla\CMS\Extension\Service\Provider\Module;
use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

/**
* The login module service provider.
*
* @since __DEPLOY_VERSION__
*/
return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Login'));
$container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Login\\Site\\Helper'));

$container->registerServiceProvider(new Module());
}
};
103 changes: 103 additions & 0 deletions modules/mod_login/src/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

/**
* @package Joomla.Site
* @subpackage mod_login
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Module\Login\Site\Dispatcher;

use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;
use Joomla\CMS\Helper\AuthenticationHelper;
use Joomla\CMS\Helper\HelperFactoryAwareInterface;
use Joomla\CMS\Helper\HelperFactoryAwareTrait;
use Joomla\CMS\Helper\ModuleHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Dispatcher class for mod_login
*
* @since __DEPLOY_VERSION__
*/
class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface
{
use HelperFactoryAwareTrait;

/**
* Runs the dispatcher.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function dispatch()
{
$this->loadLanguage();

$displayData = $this->getLayoutData();

// Stop when display data is false
if ($displayData === false) {
return;
}

// Execute the layout without the module context
$loader = static function (array $displayData) {
// If $displayData doesn't exist in extracted data, unset the variable.
if (!\array_key_exists('displayData', $displayData)) {
extract($displayData);
unset($displayData);
} else {
extract($displayData);
}

/**
* Extracted variables
* -----------------
* @var \stdClass $module
* @var Registry $params
*/

// Logged users must load the logout sublayout
if (!$user->guest) {
$layout .= '_logout';
}

require ModuleHelper::getLayoutPath('mod_login', $layout);
};

$loader($displayData);
}

/**
* Returns the layout data.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
protected function getLayoutData()
{
$data = parent::getLayoutData();
$helper = $this->getHelperFactory()->getHelper('LoginHelper');

$data['params']->def('greeting', 1);

// HTML IDs
$formId = 'login-form-' . $data['module']->id;
$data['user'] = $data['app']->getIdentity();
$type = $helper->getUserType($data['user']);
$data['return'] = $helper->getReturnUrlString($data['params'], $type, $data['app']);
$data['registerLink'] = $helper->getRegistrationUrlString($data['params'], $data['app']);
$data['extraButtons'] = AuthenticationHelper::getLoginButtons($formId);
$data['layout'] = $data['params']->get('layout', 'default');

return $data;
}
}
85 changes: 75 additions & 10 deletions modules/mod_login/src/Helper/LoginHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

namespace Joomla\Module\Login\Site\Helper;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\User\User;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -28,14 +31,17 @@ class LoginHelper
/**
* Retrieve the URL where the user should be returned after logging in
*
* @param \Joomla\Registry\Registry $params module parameters
* @param string $type return type
* @param Registry $params module parameters
* @param string $type return type
* @param CMSApplicationInterface $app The application
*
* @since __DEPLOY_VERSION__
*
* @return string
*/
public static function getReturnUrl($params, $type)
public function getReturnUrlString(Registry $params, $type, CMSApplicationInterface $app): string
{
$item = Factory::getApplication()->getMenu()->getItem($params->get($type));
$item = $app->getMenu()->getItem($params->get($type));

// Stay on the same page
$url = Uri::getInstance()->toString();
Expand All @@ -56,30 +62,34 @@ public static function getReturnUrl($params, $type)
/**
* Returns the current users type
*
* @param User $user The user object
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
public static function getType()
public function getUserType(User $user): string
{
$user = Factory::getUser();

return (!$user->guest) ? 'logout' : 'login';
}

/**
* Retrieve the URL for the registration page
*
* @param \Joomla\Registry\Registry $params module parameters
* @param Registry $params module parameters
*
* @since __DEPLOY_VERSION__
*
* @return string
*/
public static function getRegistrationUrl($params)
public function getRegistrationUrlString(Registry $params, CMSApplicationInterface $app): string
{
$regLink = 'index.php?option=com_users&view=registration';
$regLinkMenuId = $params->get('customRegLinkMenu');

// If there is a custom menu item set for registration => override default
if ($regLinkMenuId) {
$item = Factory::getApplication()->getMenu()->getItem($regLinkMenuId);
$item = $app->getMenu()->getItem($regLinkMenuId);

if ($item) {
$regLink = 'index.php?Itemid=' . $regLinkMenuId;
Expand All @@ -92,4 +102,59 @@ public static function getRegistrationUrl($params)

return $regLink;
}

/**
* Retrieve the URL where the user should be returned after logging in
*
* @param Registry $params module parameters
* @param string $type return type
*
* @return string
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getReturnUrlString
* Example: Factory::getApplication()->bootModule('mod_login', 'site')
* ->getHelper('LoginHelper')
* ->getReturnUrlString($params, $type, Factory::getApplication())
*/
public static function getReturnUrl($params, $type)
{
return (new self())->getReturnUrlString($params, $type, Factory::getApplication());
}

/**
* Returns the current users type
*
* @return string
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getUserType
* Example: Factory::getApplication()->bootModule('mod_login', 'site')
* ->getHelper('LoginHelper')
* ->getUserType(Factory::getApplication())
*/
public static function getType()
{
$user = Factory::getApplication()->getIdentity();

return (new self())->getUserType($user);
}

/**
* Retrieve the URL for the registration page
*
* @param Registry $params module parameters
*
* @return string
*
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0
* Use the non-static method getRegistrationUrlString
* Example: Factory::getApplication()->bootModule('mod_login', 'site')
* ->getHelper('LoginHelper')
* ->getRegistrationUrlString($params, Factory::getApplication())
*/
public static function getRegistrationUrl($params)
{
return (new self())->getRegistrationUrlString($params, Factory::getApplication());
}
}
Loading