public function __construct() { $this->db = Lib_Registry::get('db'); $tbl1 = $this->db->fetchCol('SHOW COLUMNS FROM auth'); $tbl2 = $this->db->fetchCol('SHOW COLUMNS FROM useraccounts'); $this->fields = array_merge($tbl1, $tbl2); }
public function put() { if (!($id = $this->getRequest()->getId())) { $this->getResponse()->setBody(array('status' => 'failed', 'message' => 'ID required')); return; } $db = Lib_Registry::get('db'); $password = $this->getRequest()->getParam('password', false); if (!$password) { $this->getResponse()->setBody(array('status' => 'failed', 'message' => 'Required parameter: password')); return; } // verify if the account exists $res = $db->fetchRow("SELECT UUID,passwordHash,passwordSalt FROM auth WHERE UUID=\"{$id}\""); if (!$res) { $this->getResponse()->setBody(array('status' => 'failed', 'message' => 'Account not found')); return; } Lib_Registry::get('db')->update('auth', array('passwordHash' => md5(md5($password) . ':' . $res['passwordSalt'])), "UUID=\"{$id}\""); $this->getResponse()->setBody(array('status' => 'success', 'message' => 'Password updated')); }
/** * Loads properties from the superglobal arrays. * * Fetches information from the SUPER GLOBAL arrays, normalizes HTTP header * keys and handles magic quotes. * * @access protected */ protected function _setArgs() { /** * Create a mock global array here for looping and setting from next * * For some reason PHP is being a twit and not letting me set this array * in the call to each. But it will let me make an array then send the * array as a variable to each, so we are going to do that. */ $globs = array('get', 'post', 'cookie', 'files'); /** * Loop through a mock global array (without getting SERVER or ENV vars) * and check to see if there is anything that needs fetching from them. */ while (list(, $prop) = each($globs)) { // Makes a "get" into a "_GET" $var = '_' . strtoupper($prop); /** * Is this var in the GLOBAL array (ex. $GLOBALS["_GET"])? * * This will work on POST, GET, COOKIE and FILES all the time. If * there is no known reference to $_ENV or $_SERVER, they will not * be in the GLOBAL array. */ if (isset($GLOBALS[$var])) { // Add it to the object property arrays (ex. $this->get = $GLOBALS["_GET"]) $this->{$prop} = $GLOBALS[$var]; } } // Now get $_SERVER and $_ENV vars foreach ($_SERVER as $k => $v) { $this->server[$k] = $v; } foreach ($_ENV as $k => $v) { $this->env[$k] = $v; } // Undo magic quotes if they are enabled. // More information can be found: // http://talks.php.net/show/php-best-practices/26 if (get_magic_quotes_gpc()) { $in = array(&$_GET, &$_POST, &$_COOKIE); while (list($k, $v) = each($in)) { foreach ($v as $key => $val) { if (!is_array($val)) { $in[$k][$key] = stripslashes($val); continue; } $in[] =& $in[$k][$key]; } } unset($in); } // load the object argv request var $this->argv = (array) $this->server('argv'); // load the object http request var foreach ($this->server as $key => $val) { // We are only interested in the HTTP_* family if (substr($key, 0, 5) == 'HTTP_') { // normalize the header key to lower-case $nicekey = strtolower(str_replace('_', '-', substr($key, 5))); // strip control characters from keys and values $nicekey = preg_replace('/[\\x00-\\x1F]/', '', $nicekey); $this->http[$nicekey] = preg_replace('/[\\x00-\\x1F]/', '', $val); // no control characters wanted in $this->server for these $this->server[$key] = $this->http[$nicekey]; // disallow external setting of X-JSON headers. if ($nicekey == 'x-json') { unset($this->http[$nicekey]); unset($this->server[$key]); } } } /** * Handle the URI bits now * * I am doing this as part of the request so I don't have to weigh the * library down with a URI object. */ // build a default scheme (with '://' in it) $ssl = $this->server('HTTPS', 'off'); $scheme = ($ssl == 'on' ? 'https' : 'http') . '://'; // get the current host $host = $this->server('HTTP_HOST'); // Make a URL of this site for use throughout $url = $scheme . $host; // Make a URL for this request for use throughout $uri = $url . $_SERVER['REQUEST_URI']; // Set up the parse_url parts $parts = array('scheme' => null, 'host' => null, 'port' => null, 'user' => null, 'pass' => null, 'path' => null, 'query' => null, 'fragment' => null); // And put them together $this->uri = array_merge($parts, parse_url($uri)); // Add our own two cents, starting with the base uri $this->uri['base'] = $url; // Now add the full, requested uri $this->uri['full'] = $uri; /** * Now set some basics of the request, like the page name, action and * param list */ $request = explode('/', trim($this->server('REQUEST_URI'), '/')); // Get the registry and config objects $registry = Lib_Registry::getInstance(); $config = $registry->get('libconfig'); // Initialize our request vars $page = $config->default->page; $action = $config->default->action; $params = array(); // If we have a requested page set it if (!empty($request[0])) { $page = strtolower($request[0]); // If we have a requested action, set that too$class, if (!empty($request[1])) { $action = strtolower($request[1]); // Lastly if we have any params, handle those if (!empty($request[2])) { for ($i = 2, $j = 3, $max = count($request); $i < $max; $i += 2, $j += 2) { $params[$request[$i]] = array_key_exists($j, $request) ? $request[$j] : null; } } } } // Set them into the uri property $this->uri['page'] = $page; $this->uri['action'] = $action; $this->uri['params'] = $params; // Read the page, action and params into the registry and be done $registry->set('page', $page); $registry->set('action', $action); $registry->set('params', $params); }
public function __construct() { $this->db = Lib_Registry::get('db'); }
<?php // admin db account $adapter = 'mysql'; $host = 'host'; $user = '******'; $password = '******'; $dbname = 'DBNAME'; Lib_Registry::set('db', new Lib_Db($adapter, $host, $user, $password, $dbname));