Recapitulation/Recipe (for use after a fresh install of CakePHP 4.0.5):
-
Install plugin.
composer require cakephp/authentication:^2.0
Installs plugin authentication in ‘./vendor/cakephp/authentication’. -
Load the plugin.
Edit ‘./src/Application.php’.
Add use of authentication.
Expand function ‘bootstrap’.
Add function ‘getAuthenticationService’.
Expand function ‘middleware’. -
Load the authentication component.
Edit ‘./src/Controller/AppController.php’.
Expand function ‘initialize’. -
Make it possible to access pages without having to log in (for example home.php on localhost:8765).
Edit ‘./src/Controller/PagesController.php’.
Add function ‘beforeFilter’. The action to allowUnauthenticated is ‘display’. -
Make it possible to ‘index’ and ‘view’ of TableX without having to log in.
Edit ‘./src/Controller/TableXController.php’.
Add function ‘beforeFilter’. -
Add a Users-table (email, password) to the database .
-
Generate MVC Users
Do the ‘cake bake all users’. -
Create login- en logout-function.
Edit ‘./src/Controller/UsersController.php’.
Add function ‘beforeFilter’ to make it possible to login and add a new user withouth having to be logged in.
Add function ‘login’ .
Add function ‘logout’. -
Create the login-page.
Add the code below the sentence ‘Add the template logic for your login action’ on the CMS Tutorial - Authentication page to a new file ‘./templates/Users/login.php’. -
Enable password hasher.
Edit ‘.scr/Model/Entity/User.php’.
Add use of PasswordHasher.
Add function _setPassword.