From 46dcd3589b11224f77389cd40aedaa975cf5a403 Mon Sep 17 00:00:00 2001 From: Robin de Graaf Date: Sun, 2 Apr 2017 14:27:38 +0200 Subject: [PATCH] Fixed two small issues, added one method on Authentication. See CHANGELOG.md for details. --- CHANGELOG.md | 14 ++++++++++++++ src/Auth/Authentication.php | 23 ++++++++++++++++++----- src/Framework/App.php | 2 +- src/Framework/Dispatcher.php | 4 +++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 687fe0d3..181e301f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Parable PHP Framework Changelog +### 0.9.4 + +__Changes__ +- Added `generatePasswordHash()` to `\Parable\Auth\Authentication`. + +__Bugfixes__ +- Fixed issue in `\Parable\Auth\Authentication` where without authentication data, a non-existing array key was read. Now that's a reason to say someone isn't validated. This only happened when calling `authenticate` and the password validating correctly. +- `\Parable\Framework\Dispatcher` can now handle nested namespaced controllers for default template files. So `Controller\Subnamespace\Home` will attempt to load `app/view/Subnamespace/Home/action.phtml`. + +### 0.9.3 + +__Bugfixes__ +- `\Parable\Http\Values\GetSet` incorrectly set the local resource when using `setAll()`. + ### 0.9.2 __Changes__ diff --git a/src/Auth/Authentication.php b/src/Auth/Authentication.php index 3abb0189..bd39ce38 100644 --- a/src/Auth/Authentication.php +++ b/src/Auth/Authentication.php @@ -4,7 +4,7 @@ class Authentication { - /** @var null|\Model\User */ + /** @var null|\Model\Users */ protected $user; /** @var \Parable\Framework\Toolkit */ @@ -38,8 +38,11 @@ public function initialize() { if ($this->checkAuthentication()) { $data = $this->getAuthenticationData(); + if (!isset($data['user_id'])) { + return false; + } $userId = $data['user_id']; - $user = $this->toolkit->getRepository(\Model\User::class)->getById($userId); + $user = $this->toolkit->getRepository(\Model\Users::class)->getById($userId); if (!$user) { $this->setAuthenticated(false); $this->setAuthenticationData([]); @@ -51,6 +54,16 @@ public function initialize() return false; } + /** + * @param $password + * + * @return bool|string + */ + public function generatePasswordHash($password) + { + return password_hash($password, PASSWORD_DEFAULT); + } + /** * Checks whether there's an auth session * @@ -116,11 +129,11 @@ public function getAuthenticationData() /** * Set the authenticated user entity * - * @param \Model\User $user + * @param \Model\Users $user * * @return $this */ - public function setUser(\Model\User $user) + public function setUser(\Model\Users $user) { $this->user = $user; return $this; @@ -129,7 +142,7 @@ public function setUser(\Model\User $user) /** * Return the user entity * - * @return null|\Model\User + * @return null|\Model\Users */ public function getUser() { diff --git a/src/Framework/App.php b/src/Framework/App.php index 8121a7fd..580ca04a 100644 --- a/src/Framework/App.php +++ b/src/Framework/App.php @@ -35,7 +35,7 @@ class App protected $database; /** @var string */ - protected $version = '0.9.2'; + protected $version = '0.9.4'; public function __construct( \Parable\Filesystem\Path $path, diff --git a/src/Framework/Dispatcher.php b/src/Framework/Dispatcher.php index f9e43fba..7bfc4493 100644 --- a/src/Framework/Dispatcher.php +++ b/src/Framework/Dispatcher.php @@ -64,8 +64,10 @@ public function dispatch(\Parable\Routing\Route $route) } else { if ($controller) { $reflection = new \ReflectionClass($controller); + $controllerName = str_replace('\\', '/', $reflection->getName()); + $controllerName = str_replace('Controller/', '', $controllerName); $templateFile = $this->path->getDir( - 'app/View/' . $reflection->getShortName() . '/' . $route->action . '.phtml' + 'app/View/' . $controllerName . '/' . $route->action . '.phtml' ); } }