function logon($login, $password) { $controller = new userDAO(); $user = $controller->getUser($login, $password); if ($user) { session_start(); $_SESSION['login'] = $user->getLogin(); $_SESSION['privilege'] = $user->getPrivilege(); header('Location: ../admin/view/reserve/reserve.php'); } else { header('Location: ../admin/login.php?ms=0'); exit("0"); } }
/** * Este metodo se llama cuando el usuario quiere modificar su contraseña * * @return void */ public function modificarContrasena() { if (!isset($this->currentUser)) { throw new Exception("Not in session. Editing posts requires login"); } $user = new User(); if (isset($_POST["password"])) { // Guarda los datos introducidos por POST en el objeto $user->setEmail($this->currentUser->getEmail()); $user->setPassword($_POST["password"]); try { // mira si los datos son correctos y si no lo son lanza excepcion $user->checkIsValidForUpdate($_POST["password2"]); // Guarda el usuario en la base de datos $this->userDAO->updatePassword($user); // Redirige al metodo login del controlador de usuarios $this->view->redirect("posts", "viewPosts"); } catch (ValidationException $ex) { // Get the errors array inside the exepction... $errors = $ex->getErrors(); // And put it to the view as "errors" variable $this->view->setVariable("errors", $errors); } } // renderiza la vista (/view/users/modificar.php) $this->view->render("users", "modificar"); }
public static function checkLogin($username, $wachtwoord) { $user = userDAO::getByUsername($username); if (isset($user) && $user->getWachtwoord() == $wachtwoord) { return true; } else { return false; } }
$rows[] = $result; } return $rows; } public function update($keyedArray) { $sql = "update {$this->_tableName} set "; foreach ($keyedArray as $column => $value) { $updates[] = "{$column} = '{$value}' "; } $sql .= implode(",", $updates); $sql .= "where {$this->_primaryKey}='{$keyedArray[$this->_primaryKey]}'"; mysql_query($sql, $this->__connection); } } class userDAO extends baseDAO { protected $_tableName = "userTable"; protected $_primaryKey = "id"; public function getUserByFirstName($name) { $result = $this->fetch($name, 'firstName'); return $result; } } $user = new userDAO(); $id = 1; $userInfo = $user->fetch($id); $updates = array('id' => 1, 'firstName' => 'arlon'); $user->update($updates); $all = $user->getUserByFirstName('arlon');
if (isset($_POST['username']) && isset($_POST['password'])) { if ($_POST['username'] == "" || $_POST['password'] == "") { $missingFields = true; } else { //All fields set, fields have a value $abstractDAO = new AbstractDAO(); if (!$abstractDAO->hasDbError()) { $username = $_POST['username']; $password = $_POST['password']; $abstractDAO->authenticate($username, $password); if ($abstractDAO->isAuthenticated()) { $_SESSION['abstractDAO'] = $abstractDAO; $_SESSION['abstractDAO']->setAdminID(1); $_SESSION['abstractDAO']->setAdminLevel('Administrator'); /*Here I will add the username and password and other info to the adminuser DB and later retrieve it in internal*/ $userDAO = new userDAO(); /* $username = $_POST['username']; $password = $_POST['password']; $adminLevel = 'Administrator';*/ $userDAO->insertUser(null, $_POST['username'], $_POST['password'], 'Administrator', null); header('Location:internal.php'); } } } } } ?> <?php
$sql = "update {$this->_tableName} set "; $updates = array(); foreach ($keyedArray as $column => $value) { $updates[] = "{$column} = '{$value}'"; } $sql .= implode(',', $updates); $sql .= "where {$this->_primaryKey} = '{$keyedArray[$this->_primaryKey]}'"; mysql_query($sql, $this->__connection); } } class userDAO extends baseDAO { protected $_tableName = 'userTable'; protected $_primaryKey = 'id'; public function getUserByFirstName($name) { $result = $this->fetch($name, 'firstName'); return $result; } } define('DB_USER', 'root'); define('DB_PASS', 'root'); define('DB_HOST', 'localhost'); define('DB_DATABASE', 'test'); $user = new userDAO(); $userDetailsArray = $user->fetch(1); print_r($userDetailsArray); $updates = array('id' => 1, 'firstName' => 'aaron'); $user->update($updates); $allAarons = $user->getUserByFirstName('aaron'); print_r($allAarons);