CodeIgniter Forums
Is there a better way to custom Shield login form? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Is there a better way to custom Shield login form? (/showthread.php?tid=86769)



Is there a better way to custom Shield login form? - Snackys - 02-16-2023

Hello everyone,

I am implementing Shield, and I would like to customize the login form.

Following the documentation I started to add and update the router in Routes.php file:
PHP Code:
$routes->get('login''\App\Controllers\Auth\LoginController::loginView');
$routes->post('login''\App\Controllers\Auth\LoginController::loginAction'); 

PHP Code:
service('auth')->routes($routes, ['except' => ['login']]); 

Then I added the custom controller in App/Controllers/Auth/LoginController.php with the following namespace:
PHP Code:
namespace App\Controllers\Auth

Here is the body of my custom LoginController controller:
PHP Code:
<?php

namespace App\Controllers\Auth;

use 
CodeIgniter\Shield\Controllers\LoginController as ShieldLogin;
use 
CodeIgniter\Shield\Authentication\Authenticators\Session;
use 
CodeIgniter\HTTP\RedirectResponse;

class 
LoginController extends ShieldLogin
{
    public function loginView()
    {
        // Same code of the parent method
    }

    public function loginAction(): RedirectResponse
    
{
        // Same code of the parent method
    }


Everything works fine. I have the default form as expected for my tests.

So my question is the following:
Is there another way to only custom the form appearance without override the loginAction post method?

Thank you!


RE: Is there a better way to custom Shield login form? - datamweb - 02-16-2023

(09-14-2022, 10:58 AM)lokman Wrote: only custom the form appearance without override the loginAction post method?

If you mean to change the login form view.
What you have done is not needed.
See the link below :
https://github.com/codeigniter4/shield/discussions/480