PHP code example of falco442 / slim-token-auth-mvc

1. Go to this page and download the library: Download falco442/slim-token-auth-mvc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

falco442 / slim-token-auth-mvc example snippets


return [
    'settings' => [
        '...',
        'determineRouteBeforeAppMiddleware'=>true, //Allows to catch the route from middleware

        'db' => [			// Pass the DB configuration
            'driver' => 'mysql',
            'host' => 'localhost',
            'database' => 'db_test',
            'username' => 'test',
            'password' => 'test',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ],
        'auth'=>[
            'table' => 'users',	// the table in which you can find users to authenticate
            'salt'  => 'asdasdkhkhuilyuhg1i8y9p78olil',	// the custom salt to hash the passwords
            'allowed_routes'=>[
                'POST'=>[
                	'/login', 	// to allow login
                	'/users'	// to allow adding a user
                ]
            ],
            'fields'=>[
                'username'=>'username',		// you can set anything you want.. like 'username' => 'email' if you want to login users by email
                'password'=>'password'		// same thing as above
            ]
        ],
        '...'
    ],
];

$app->any('/login', '\App\Controller\UsersController:login');

public function login($request,$response,$args){
	return $response->withJSON($this->Auth->authenticate($request));
}