Пример #1
0
 public function initDatabase()
 {
     $this->db = \Core\Db::create("mysql");
     // create table (demo pour mysql)
     $sql = "\n            CREATE TABLE IF NOT EXISTS `role` (\n              `idrole` int(11) NOT NULL AUTO_INCREMENT,\n              `role` varchar(45) DEFAULT NULL,\n              PRIMARY KEY (`idrole`)\n            )\n        ";
     $this->db->query($sql);
     $sql = "\n            CREATE TABLE IF NOT EXISTS `countries` (\n                `id` int(11) NOT NULL auto_increment,\n                `country_code` varchar(2) NOT NULL default '',\n                `country_name` varchar(100) NOT NULL default '',\n                PRIMARY KEY (`id`)\n            )\n        ";
     $this->db->query($sql);
     $sql = "\n            CREATE TABLE IF NOT EXISTS `user` (\n              `iduser` int(11) NOT NULL AUTO_INCREMENT,\n              `nom` varchar(45) NOT NULL,\n              `password` varchar(45) DEFAULT NULL,\n              `role` int(11) DEFAULT NULL,\n              `datetime` datetime DEFAULT NULL,\n              `date` date DEFAULT NULL,\n              `time` time DEFAULT NULL,\n              `float` float DEFAULT NULL,\n              `description` text,\n              `pays` int(11) DEFAULT NULL,\n              PRIMARY KEY (`iduser`),\n              UNIQUE KEY `nom_UNIQUE` (`nom`),\n              KEY `fk_user_role` (`role`),\n              KEY `fk_user_pays` (`pays`),\n              CONSTRAINT `fk_user_pays` FOREIGN KEY (`pays`) REFERENCES `countries` (`id`),\n              CONSTRAINT `fk_user_role` FOREIGN KEY (`role`) REFERENCES `role` (`idrole`)\n            )\n        ";
     $this->db->query($sql);
 }
Пример #2
0
 public function __construct($params = array())
 {
     parent::__construct($params);
     $db = null;
     if (isset($this->params["database"])) {
         $db = $this->params["database"];
     }
     $this->db = \Core\Db::create($db);
     $this->table = $this->params["table"];
     $this->describe = $this->db->describe($this->table);
     $this->primaryKey = null;
     foreach ($this->describe as $desc) {
         if ($desc["primaryKey"]) {
             $this->primaryKey = $desc["name"];
         }
     }
     if ($this->primaryKey === null) {
         throw new \Core\CException("TableManager : Table " . $this->table . " have no primary key");
     }
     $this->SetColumns();
 }
Пример #3
0
<?php

$params = $self->getUsersConfig();
$table = $params["roleTable"];
$database = $params["database"];
$db = \Core\Db::create($database);
$fields = $db->describe($table);
$tblParams = array();
foreach ($fields as $field => $aField) {
    $tblParams[$field] = array("showInTable" => false);
}
$tblParams[$params["roleId"]] = array("alias" => "", "link" => true);
$tblParams[$params["roleField"]] = array("alias" => "Role", "link" => true);
echo \Core\Module::create("core/Admin/TableManager", array("database" => $database, "table" => $table, "columns" => $tblParams))->render();
Пример #4
0
 protected function loginAction($options = array())
 {
     // Default option value
     // passwordEncrypt = true
     $options["passwordEncrypt"] = isset($options["passwordEncrypt"]) ? $options["passwordEncrypt"] : true;
     // force l'envoi de la clé
     $this->testKey(true);
     if (empty($_REQUEST->login) || empty($_REQUEST->password)) {
         throw new \Core\CException("Login failed");
     }
     $db = \Core\Db::create($this->getParams("database"));
     $userTable = $db->quoteTable($this->getParams("userTable", "table"));
     $idField = $db->quoteField($this->getParams("userTable", "idField"));
     $loginField = $db->quoteField($this->getParams("userTable", "loginField"));
     $passwordField = $db->quoteField($this->getParams("userTable", "passwordField"));
     $passwordFn = $this->getParams("userTable", "passwordFn");
     $nameField = $db->quoteField($this->getParams("userTable", "nameField"));
     $roleTable = $db->quoteTable($this->getParams("roleTable", "table"));
     $roleId = $db->quoteField($this->getParams("roleTable", "idField"));
     $roleField = $db->quoteField($this->getParams("roleTable", "roleField"));
     $linkTable = $db->quoteTable($this->getParams("linkTable", "table"));
     $linkUser = $db->quoteField($this->getParams("linkTable", "userId"));
     $linkRole = $db->quoteField($this->getParams("linkTable", "roleId"));
     //if(! \Core\CString::isValidMd5($_REQUEST->password)) {
     if ($options["passwordEncrypt"] === true && !empty($passwordFn)) {
         $_REQUEST->password = call_user_func($passwordFn, $_REQUEST->password);
     }
     $randId = strtolower(\Core\CString::rand(5));
     $sql = "\n            SELECT\n                {$idField} as userid_{$randId},\n                {$loginField} as userlogin_{$randId},\n                {$nameField} as username_{$randId},\n                u.*\n            FROM\n                {$userTable} u\n            WHERE\n                u.{$loginField} = :user\n                AND u.{$passwordField} = :Login\n        ";
     $res = $db->selectRow($sql, array(":user" => $_REQUEST->login, ":Login" => $_REQUEST->password));
     if (!empty($res)) {
         \Core\Security::setUserId($res["userid_" . $randId]);
         \Core\Security::setUserLogin($res["userlogin_" . $randId]);
         \Core\Security::setUserName($res["username_" . $randId]);
         $resUser = $res;
         unset($resUser["userid_" . $randId]);
         unset($resUser["userlogin_" . $randId]);
         unset($resUser["username_" . $randId]);
         \Core\Security::setUser($resUser);
         // Reccup role
         $sql = "\n                SELECT \n                    r.{$roleField} as role\n                FROM\n                    {$roleTable} r\n               JOIN\n                    {$linkTable} l\n                        ON r.{$roleId} = l.{$linkRole}\n               JOIN\n                    {$userTable} u\n                        ON u.{$idField} = l.{$linkUser}\n               WHERE\n                    u.{$idField} = :userid\n            ";
         $resRole = $db->select($sql, array(":userid" => $res["userid_" . $randId]));
         if (!empty($resRole)) {
             foreach ($resRole as $role) {
                 \Core\Security::AddRole($role["role"]);
             }
         }
         // St cookie for Autologin
         if (isset($_REQUEST->autologin) && $_REQUEST->autologin == "1") {
             $c = array($_REQUEST->login, $_REQUEST->password);
             $c = serialize($c);
             $c = \Core\CString::encrypt($c, $this->cookieName);
             setcookie($this->cookieName, $c, time() + $this->cookieTime, "/");
         }
     } else {
         $this->logout(new \Core\Request());
         throw new \Core\CException("Login failed");
     }
 }
Пример #5
0
 public function getUsersConfig()
 {
     $db = \Core\Db::create($this->getUserParams("database"));
     return array("db" => $db, "database" => $this->getUserParams("database"), "userTable" => $this->getUserParams("userTable", "table"), "idField" => $this->getUserParams("userTable", "idField"), "loginField" => $this->getUserParams("userTable", "loginField"), "passwordField" => $this->getUserParams("userTable", "passwordField"), "passwordFn" => $this->getUserParams("userTable", "passwordFn"), "nameField" => $this->getUserParams("userTable", "nameField"), "roleTable" => $this->getUserParams("roleTable", "table"), "roleId" => $this->getUserParams("roleTable", "idField"), "roleField" => $this->getUserParams("roleTable", "roleField"), "linkTable" => $this->getUserParams("linkTable", "table"), "linkUser" => $this->getUserParams("linkTable", "userId"), "linkRole" => $this->getUserParams("linkTable", "roleId"));
 }