public function checkUsername($username) { try { $admin = new \Model\Admin(); $admin->findByCriteria(array("username" => $username)); if ($admin->id != $this->id) { return false; } } catch (\Exception $e) { //nothing } return true; }
public function Authenticate($username, $password) { try { $db = \Registry::get("db"); $admin = new \Model\Admin(); $admin->findByCriteria(array("username" => $username)); if ($admin->id && crypt($password, $admin->password) == $admin->password) { $_SESSION['admin_id'] = $admin->id; return $admin; } } catch (\RuntimeException $ex) { return false; } return false; }
public function deleteAdmin(\Request $req, \Response $res) { $admin = new \Model\Admin($req->param("id")); $admin->deleteFromDb(); $res->Json(array("message" => "Admin successfully deleted")); }
<?php $user = $argv[1]; $pass = $argv[2]; $email = $argv[3]; error_reporting(E_ALL); ini_set("display_errors", 1); define("APP_ROOT", __DIR__ . "/.."); require_once __DIR__ . "/../Classes/Autoloader.php"; $config = new \Config("config"); $db = new \Database($config->database); Registry::add("config", $config); Registry::add("db", $db); $admin = new \Model\Admin(); $admin->username = $user; $admin->password = crypt($pass); $admin->email = $email; $admin->write();