PHP code example of atk4 / login

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

    

atk4 / login example snippets


$app = new \Atk4\Ui\App();
$app->initLayout([\Atk4\Ui\Layout\Admin::class]);
$app->db = new \Atk4\Data\Persistence($dsn);

// ADD THIS CODE:
$app->auth = new \Atk4\Login\Auth($app);
$app->auth->setModel(new \Atk4\Login\Model\User($app->db));

// The rest of YOUR UI code will now be protected
\Atk4\Ui\Crud::addTo($app)->setModel(new Client($app->db));

$app->auth = new \Atk4\Login\Auth($app, [
    'hasPreferences' => false, // do not show Preferences page/form
    'pageDashboard' => 'dashboard', // name of the page, where user arrives after login
    'pageExit' => 'goodbye', // where to send user after logout

    // Oter options:
    // 'hasUserMenu' => false, // will disable interaction with Admin Layout user menu
]);
$app->auth->setModel(new User($app->db));
 php
$app->auth = new \Atk4\Login\Auth($app, [
    'check' => false,
]);
$app->auth->setModel(new User($app->db));


// Now manually use login logic
if (!$app->auth->user->isLoaded()) {
    \Atk4\Login\LoginForm::addTo($app, ['auth' => $app->auth]);
}
 php
\Atk4\Login\RegisterForm::addTo($app)
    ->setEntity(new \Atk4\Login\Model\User($app->db));
 php
\Atk4\Login\LoginForm::addTo($app, [
    'auth' => $app->auth,
    // 'successLink' => ['dashboard'],
    // 'forgotLink' => ['forgot'],
]);
 php
if ($app->auth->user->isLoaded()) {
    // logged-in
}
 php
Form::addTo($app)->setEntity($app->auth->user);
 php
Button::addTo($app, ['Profile', 'class.primary' => true])
    ->on('click', Modal::addTo($app)->set(function (View $p) {
        Form::addTo($p)->setEntity($p->getApp()->auth->user);
    })->jsShow());
 php
$model->addField('password', [\Atk4\Data\Field\PasswordField::class]);
 php
\Atk4\Login\UserAdmin::addTo($app)
    ->setModel(new \Atk4\Login\Model\User($app->db));