Skip to content

Instantly share code, notes, and snippets.

@abbadon1334
Last active February 26, 2019 14:53
Show Gist options
  • Save abbadon1334/9b02817cc539158017890b474dc48a27 to your computer and use it in GitHub Desktop.
Save abbadon1334/9b02817cc539158017890b474dc48a27 to your computer and use it in GitHub Desktop.
Andrea atk4
<?php
include '../common.php';
class MyApp extends \atk4\ui\App
{
public $db;
public $auth;
public $title = 'My App Control Panel';
public $dsn = 'sqlite:/tmp/foo1.db';
function __construct($interface = 'front')
{
// parent::__construct(include('config.php'));
parent::__construct();
$this->initLayout('Admin');
$this->layout->leftMenu->addItem([
'Customer',
'icon' => 'gift',
], ['customer']);
$this->layout->leftMenu->addItem([
'Subscriptions',
'icon' => 'users',
], ['subscription']);
$this->dbConnect($this->dsn);
}
function authenticate()
{
$this->auth = $this->add(new \atk4\login\Auth(['check' => false]));
$this->auth->setModel(new CustomerLogin($this->db));
}
}
class CustomerLogin extends \atk4\data\Model
{
public $table = 'snp_customer_login';
public $id_field = 'id_customer';
function init()
{
parent::init();
$this->addField('email', ['type' => 'string']);
$this->addField('password');
}
}
$app = new MyApp('admin');
$model = new CustomerLogin($app->db);
// create the table in db
//(new \atk4\schema\Migration\SQLite(new CustomerLogin($app->db)))->migrate();
$data = [
'email' => 'pino',
'password' => 'lino',
];
$model->insert($data);
// manual init auth
$app->authenticate();
$t = $app->add(['Message','Currently Logged User',])->text;
// IF AUTH SHOW THE APP
if ($app->auth->user->loaded()) {
$t->addParagraph($app->auth->user['email'] . ' (' . $app->auth->user->id . ')');
$app->add([
'Button',
'Profile',
'primary',
])
->on('click', $app->add('Modal')
->set(function ($p) {
$p->add('Form')
->setModel($p->app->auth->user);
})
->show());
$app->add(['Button', 'Logout',])
->on('click', function () use ($app) {
$app->auth->logout();
return new \atk4\ui\jsExpression('document.location.reload()');
});
} else {
// IF NOT AUTH SHOW THE LOGIN FORM
$app->add([new \atk4\login\LoginForm(), 'auth'=>$app->auth]);
}
$app->add('Text')->addParagraph(print_r($_SESSION,true));
$app->add(['Button','Back',])->link(['index']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment