Created
August 22, 2012 08:23
-
-
Save Mikulas/3423745 to your computer and use it in GitHub Desktop.
Nette user login for Adminer Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adminer 5 wrapped itself into a namespace and plugins now need to call Adminer's functions via this namespace.
Please update this Gist to this: https://gist.github.com/vrana/6af5caa725bbe77316e639ea4eef761c