PHP code example of klsoft / yii3-user

1. Go to this page and download the library: Download klsoft/yii3-user 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/ */

    

klsoft / yii3-user example snippets


use Klsoft\Yii3Auth\Middleware\Authentication;
 
Route::post('/create')
        ->middleware(Authentication::class)
        ->action([SiteController::class, 'create'])
        ->name('site/create')

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Yiisoft\User\CurrentUser;

public function login(ServerRequestInterface $request): ResponseInterface
{
    // ...
    //After a successful authentication $this->currentUser->login($identity)
    $queryParams = $request->getQueryParams();
    if(isset($queryParams['redirect_uri'])) {
        return $this->responseFactory
            ->createResponse(Status::FOUND)
            ->withHeader('Location', $queryParams['redirect_uri']);
    }
}

use DateInterval;
use Klsoft\Yii3User\Login\Cookie\CookieLogin;

return [
    // ...
    CookieLogin::class => [
        '__construct()' => [
            'duration' => $params['yiisoft/user']['cookieLogin']['duration'] !== null ?
                new DateInterval($params['yiisoft/user']['cookieLogin']['duration']) :
                null,
        ],
        'withCookieSecure()' => [false]
    ],
];