Welcome Guest, Not a member yet? Register   Sign In
Shield "Can't find a route for 'POST: login'. "
#1

Hi,

i've installed ci4 with shield.

At first i want to create a own login view for that i've create a copy of the "loginController.php" from the "vendor/codeigniter4/shield/src/controllers/" with the dirst fnction "loginView()" (its the only part wich call the "views") all other i think i can ignore an let it as original it is.

"amespace App\Controllers\Shield;

use CodeIgniter\Shield\Controllers\LoginController as ShieldLogin;
use CodeIgniter\HTTP\RedirectResponse;


class LoginController extends ShieldLogin
{
public function loginView()
{
if (auth()->loggedIn()) {
return redirect()->to(config('Auth')->loginRedirect());
}

/** @var Session $authenticator */
$authenticator = auth('session')->getAuthenticator();

// If an action has been defined, start it up.
if ($authenticator->hasAction()) {
return redirect()->route('auth-action-show');
}

//Render page (i've change a bit the way to echo and render the views)
$this->template(setting('Auth.views')['login'], array(), array('title'=>'4U.tools - Login'), array('mode'=>'fullpage'));
}
}"

Also in my "app/Config/Routes.php", i've added this
"use CodeIgniter\Router\RouteCollection;

/**
* @var RouteCollection $routes
*/
$routes->get('/', 'Home::index');

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

//Authentification by shield
$routes->get('login', '\App\Controllers\Shield\LoginController::loginView');"

Now on mydomain.tld/login is see my own view.

If i submit the form i get the "404 Can't find a route for 'POST: login'. " error message.

I think i have to change more as i already done. Have i add each of the following parts also to my "app/Config/Routes.php"?
If so, is there a way to make it easier, with less code?


+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| Method | Route | Name | Handler | Before Filters | After Filters |
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| GET | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerView | | toolbar |
| GET | {locale}/login | login | \CodeIgniter\Shield\Controllers\LoginController::loginView | | toolbar |
| GET | {locale}/login/magic-link | magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::loginView | | toolbar |
| GET | {locale}/login/verify-magic-link | verify-magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::verify | | toolbar |
| GET | {locale}/logout | logout | \CodeIgniter\Shield\Controllers\LoginController::logoutAction | | toolbar |
| GET | {locale}/auth/a/show | auth-action-show | \CodeIgniter\Shield\Controllers\ActionController:Confusedhow | | toolbar |
| POST | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerAction | | toolbar |
| POST | {locale}/login | » | \CodeIgniter\Shield\Controllers\LoginController::loginAction | | toolbar |
| POST | {locale}/login/magic-link | » | \CodeIgniter\Shield\Controllers\MagicLinkController::loginAction | | toolbar |
| POST | {locale}/auth/a/handle | auth-action-handle | \CodeIgniter\Shield\Controllers\ActionController::handle | | toolbar |
| POST | {locale}/auth/a/verify | auth-action-verify | \CodeIgniter\Shield\Controllers\ActionController::verify | | toolbar |
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
Reply
#2

In sheild/src/Config/Auth.php did you change it to your view?

PHP Code:
    /**
    * --------------------------------------------------------------------
    * View files
    * --------------------------------------------------------------------
    */
    public array $views = [
        'login'                      => '\CodeIgniter\Shield\Views\login',
        'register'                    => '\CodeIgniter\Shield\Views\register',
        'layout'                      => '\CodeIgniter\Shield\Views\layout',
        'action_email_2fa'            => '\CodeIgniter\Shield\Views\email_2fa_show',
        'action_email_2fa_verify'    => '\CodeIgniter\Shield\Views\email_2fa_verify',
        'action_email_2fa_email'      => '\CodeIgniter\Shield\Views\Email\email_2fa_email',
        'action_email_activate_show'  => '\CodeIgniter\Shield\Views\email_activate_show',
        'action_email_activate_email' => '\CodeIgniter\Shield\Views\Email\email_activate_email',
        'magic-link-login'            => '\CodeIgniter\Shield\Views\magic_link_form',
        'magic-link-message'          => '\CodeIgniter\Shield\Views\magic_link_message',
        'magic-link-email'            => '\CodeIgniter\Shield\Views\Email\magic_link_email',
    ]; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB