且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Joomla 3 尝试错误登录后重定向

更新时间:2023-11-27 08:23:52

您将需要修改用户控制器.但是为了保持更新证明",您不能修改核心代码,这就是我们将进行覆盖的原因:

  1. components/com_users/controllers/复制一个名为user.php的文件,你可以调用一个新文件user2.php
  2. 打开user2.php文件并将控制器类重命名为UsersControllerUser2
  3. 创建登录模块的模板覆盖(使其也更新证明),创建一个templates/YOUR_TEMPLATE/html/mod_login 文件夹并复制modules/mod_login/tmpl/default.php 文件在那里.
  4. 打开在步骤 3 中创建的文件并将登录模块任务从 <input type="hidden" name="task" value="user.login"/> 更改为 <input type="hidden" name="task" value="user2.login"/>
  5. 再次打开user2.php文件,修改这部分代码(77-82行左右):

$app->redirect(JRoute::_('index.php?option=com_users&view=login',假));

$app->redirect 路由更改为您想要的任何内容:)

Iam using the login module of Joomla. Login and Logout redirects to the pages which are set in the modul settings.

My problem is the status, where a user tries to login with wrong user credentials. In this case, the user will be redirected to component/users/?view=login page. In my case, this page is not in use and also not designed like the rest of the pages. Therefore I would like to redirect the user, after a wrong login, to the previous page.

Does anybody have a clue, how to solve that?

thx

You will need to modify users controller. But to keep it "update proof" you cannot modify the core code, thats why we will make an override:

  1. Go to the components/com_users/controllers/ and duplicate a file called user.php, you can call a new file user2.php
  2. Open user2.php file and rename controller class to UsersControllerUser2
  3. Create a template override of your login module (to make it update proof also), create a templates/YOUR_TEMPLATE/html/mod_login folder and copy modules/mod_login/tmpl/default.php file there.
  4. Open file created in step 3 and change login module task from <input type="hidden" name="task" value="user.login" /> to <input type="hidden" name="task" value="user2.login" />
  5. Open user2.php file once again, and modify this part of code (around lines 77-82):

$app->redirect(JRoute::_('index.php?option=com_users&view=login', false));

Change $app->redirect route to whatever you want :)