From b46cee71f79795f7300c275f2cfea7fca27a752d Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 7 Feb 2017 17:49:10 +0100 Subject: Web interface --- frontend/Author.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 frontend/Author.php (limited to 'frontend/Author.php') diff --git a/frontend/Author.php b/frontend/Author.php new file mode 100644 index 0000000..669e733 --- /dev/null +++ b/frontend/Author.php @@ -0,0 +1,45 @@ +pdo, ['`author_id`=?'], [$this->id]); + } + + public function getPackages() { + return Package::search($this->pdo, ['`author_id`=?'], [$this->id]); + } + + public static function hash($password) { + return password_hash($password, PASSWORD_DEFAULT, ['cost' => 10]); + } + + protected static function mutator($key, $value) { + switch ($key) { + case 'password': + return self::hash($value); + default: + return parent::mutator($key, $value); + } + } + + public function isAdmin() { + return in_array($this->id, Constants::user_admins); + } + + public function verifyPassword($password) { + if (!password_verify($password, $this->password)) + return false; + if (password_needs_rehash( + $this->password, PASSWORD_DEFAULT, ['cost' => 10])) + $this->password = $password; + return true; + } +} -- cgit v1.2.3