public function logout() { if (Service::getService()->isAuthenticated()) { Service::getService()->clearAuthenticated(); header('Location: /guestbook'); } }
public function __construct() { $pdo = Service::getService()->getPDO(); if (is_null($pdo)) { throw new ConfigExeption(); } self::$db = new \PDO($pdo['dns'], $pdo['user'], $pdo['password']); self::$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); }
public function getUser() { if ($this->load()) { $sth = $this->doStatement($this->get_user, array('username' => $this->username)); $sth->setFetchMode(\PDO::FETCH_CLASS, __CLASS__); $row = $sth->fetch(); if ($row->password === $this->password) { Service::getService()->setAuthenticate(); return true; } } return false; }
private function mainAction($active_page = 1, $message = null, GuestbookModel $model_data = null) { $model = new GuestbookModel(); $rec_num = $model->getNumberRecords(); $per_page = Service::getService()->recordsPerPage(); $pages = ceil($rec_num / $per_page); if ($active_page <= $pages || $pages == 0) { $model = (array) $model->getLimitRecords($active_page * $per_page - $per_page, $per_page); } else { throw new HttpNotFoundException("Page not found"); } return $this->render('index', $model, array('pages' => $pages, 'active_page' => $active_page, 'message' => $message, 'model_data' => $model_data)); }
public function run() { try { Service::getService()->init($this->config); $route = (array) Service::getService()->getRequestURI(); $route = array_key_exists(1, $route) ? $route[1] : ""; $controller = Controller::getController($route); $controller->defaultAction(); } catch (HttpNotFoundException $exc) { $error = "This page does not exist."; $this->errorRender($error); } catch (SecurityExeption $exc) { $error = "Permission denied."; $this->errorRender($error); } catch (ConfigExeption $exc) { $error = "Problems with config file."; $this->errorRender($error); } catch (\Exception $exc) { $error = "Something goes wrong. Go back and try again."; $this->errorRender($error); } }
public function validate($attributeNames = null) { foreach ($this->getRequired() as $key => $required) { if ($required == "") { $this->valid_errs[$key] = "Must be filled!"; return false; } } if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) { $this->valid_errs['email'] = "Invalid email format"; } if (!preg_match("/^[a-zA-Z ]*\$/", $this->name)) { $this->valid_errs['name'] = "Only letters and white space allowed"; } if ($this->website != "") { $parts = parse_url($this->website); if (!isset($parts["scheme"])) { $this->website = "http://{$this->website}"; } if (!filter_var($this->website, FILTER_VALIDATE_URL)) { $this->valid_errs['website'] = "Invalid URL"; } } if (Service::getService()->getCaptchaText() !== strtoupper($this->captcha)) { $this->valid_errs['captcha'] = "The text doesn't match. Try again"; } return count($this->valid_errs) > 0 ? false : true; }