From 267fe5cadd44b17bacc354fd4a4124becba2ebd7 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 10 Oct 2022 14:27:55 +0000 Subject: [PATCH 1/3] Fixed some loading problems with loaded user and ajusted the Email allowed length (to 255) --- src/Entity/User.php | 2 +- src/Lib/Authenticate.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Entity/User.php b/src/Entity/User.php index 9de20d0..578350d 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -22,7 +22,7 @@ class User { public ? string $lastName; /** - * @Field("size" => 150) + * @Field("size" => 255) */ public string $email; diff --git a/src/Lib/Authenticate.php b/src/Lib/Authenticate.php index 45e2b67..f38aaee 100644 --- a/src/Lib/Authenticate.php +++ b/src/Lib/Authenticate.php @@ -35,8 +35,8 @@ class Authenticate { public function rememberMe(\Ulmus\Repository $repository) : ? User { - $logUser = function(int $id) use ($repository) { - if ( null === ( $user = $repository->loadFromPk($id) ) ) { + $logUser = function(? int $id) use ($repository) { + if ( $id === null || null === ( $user = $repository->loadFromPk($id) ) ) { throw new \Exception("User not found."); } From 015f0c70b153ca5129be2845a728236e769ef570 Mon Sep 17 00:00:00 2001 From: Dave M Date: Wed, 12 Oct 2022 18:18:36 +0000 Subject: [PATCH 2/3] - hashPassword can now be used as a standalone method --- src/Entity/User.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Entity/User.php b/src/Entity/User.php index 9de20d0..a0e499e 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -85,7 +85,7 @@ class User { public function __toString() : string { - return $this->fullname(); + return "{$this->firstName} {$this->lastName}"; } public function setPassword($password) : self @@ -95,16 +95,16 @@ class User { return $this->hashPassword(); } - public function hashPassword() : self + public function hashPassword(? string $password = null) : self { - $this->password = password_hash($this->password, PASSWORD_DEFAULT); + $this->password = password_hash($password ?: $this->password, PASSWORD_DEFAULT); return $this; } public function verifyPassword(string $password) : bool { - return password_verify($password, $this->password ); + return password_verify($password, $this->password); } public function fullname() : string From cef536caa5037b375c2e676a8a31f466b506a143 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Thu, 24 Nov 2022 20:01:49 +0000 Subject: [PATCH 3/3] - Fixed a bug within the merge --- src/Entity/User.php | 22 +++++++++++----------- src/Lib/Authenticate.php | 4 +++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Entity/User.php b/src/Entity/User.php index 8725e35..c2dc25c 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -12,57 +12,57 @@ class User { public int $id; /** - * @Field("size" => 35, "name" => "first_name") + * @Field("length" => 35, "name" => "first_name") */ public ? string $firstName; /** - * @Field("size" => 35, "name" => "last_name") + * @Field("length" => 35, "name" => "last_name") */ public ? string $lastName; /** - * @Field("size" => 255) + * @Field("length" => 255) */ public string $email; /** - * @Field("size" => 150) + * @Field("length" => 150) */ public ? string $address; /** - * @Field("size" => 15, 'name' => "zip_code") + * @Field("length" => 15, 'name' => "zip_code") */ public ? string $zipCode; /** - * @Field("size" => 45) + * @Field("length" => 45) */ public ? string $province; /** - * @Field("size" => 3) + * @Field("length" => 3) */ public ? string $country; /** - * @Field("size" => 15) + * @Field("length" => 15) */ public ? string $phone; /** - * @Field("size" => 15) + * @Field("length" => 15) */ public ? string $ext; /** - * @Field("size" => 15) + * @Field("length" => 15) */ public ? string $mobile; /** - * @Field("size" => 255) + * @Field("length" => 255) */ public ? string $username; diff --git a/src/Lib/Authenticate.php b/src/Lib/Authenticate.php index f38aaee..9d02681 100644 --- a/src/Lib/Authenticate.php +++ b/src/Lib/Authenticate.php @@ -123,7 +123,9 @@ class Authenticate { $this->cookie->delete('user.id'); } - $this->user->logged = false; + if (isset($this->user)) { + $this->user->logged = false; + } return $this; }