Welcome Guest, Not a member yet? Register   Sign In
Is there a better way to custom Shield login form?
#1
Question 

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!
Si vous pouvez le rêver, vous pouvez le faire.
Reply
#2

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB