public
Last active

Nette user login for Adminer Editor

  • Download Gist
config.neon
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
common:
parameters:
adminer_editor:
role: moderator
 
database:
host: localhost
dbname: yourDbName
user: yourDbUser
password: yourDbOass
 
nette:
database:
default:
dsn: "mysql:host=%database.host%;dbname=%database.dbname%"
user: %database.user%
password: %database.password%
editor.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
<?php
 
/**
* Nette user login for Adminer Editor
* @author Mikuláš Dítě
* @license BSD-3
*
* Expects the following config.neon setup:
* common:
* parameters:
* database:
* host: localhost
* dbname: yourdbname
* user: youruser
* password: yourpass
* adminer_editor:
* role: moderator
* nette:
* database:
* default:
* dsn: "mysql:host=%database.host%;dbname=%database.dbname%"
* user: %database.user%
* password: %database.password%
*/
 
define('WWW_DIR', __DIR__ . '/..');
define('APP_DIR', WWW_DIR . '/../app');
define('LIBS_DIR', WWW_DIR . '/../libs');
 
require LIBS_DIR . '/Nette/loader.php';
 
$configurator = new Nette\Config\Configurator;
 
$configurator->setDebugMode();
$configurator->enableDebugger(APP_DIR . '/../log');
 
// Enable RobotLoader - this will load all classes automatically
$configurator->setTempDirectory(APP_DIR . '/../temp');
$configurator->createRobotLoader()
->addDirectory(APP_DIR)
->addDirectory(LIBS_DIR)
->register();
 
// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/../../app/config/config.neon');
 
$container = $configurator->createContainer();
 
$container->user->isLoggedIn();
$container->user->isInRole($container->params['adminer_editor']['role']);
 
$_GET['username'] = ''; // triggers autologin
 
function adminer_object() {
 
class AdminerSoftware extends Adminer {
 
private $context;
 
function __construct($context) {
$this->context = $context;
}
 
function name() {
// custom name in title and heading
return 'Khanova Škola';
}
 
function credentials() {
// server, username and password for connecting to database
$c = $this->context->params['database'];
return array($c['host'], $c['user'], $c['password']);
}
 
function database() {
// database name, will be escaped by Adminer
return $this->context->params['database']['dbname'];
}
 
function login() {
return $this->isLoggedIn() && $this->isInRole();
}
 
function tableName($tableStatus) {
// only tables with comment will be displayed
return h($tableStatus["Comment"]);
}
 
function fieldName($field, $order = 0) {
// only columns with comments will be displayed
// table must have at least one column with comment
// to select properly
return h($field["comment"]);
}
 
function loginForm() {
if (!$this->isLoggedIn()) {
echo "<p>Přihlaste se prosím ke svému účtu přes tradiční formulář.</p>";
} else if (!$this->isInRole()) {
echo "<p>Váš účet nemá oprávnění k Adminer Editor.</p>";
}
}
 
private function isLoggedIn() {
return $this->context->user->isLoggedIn();
}
 
private function isInRole() {
return $this->context->user->isInRole($this->context->params['adminer_editor']['role']);
}
 
}
 
global $container;
return new AdminerSoftware($container);
}
 
include "./editor-3.5.0-mysql.php";
global $container;'

No fuj :P to už radši

Nette\Environment::getContext();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.