From e04b43f0add00a1467cd9222e099be3fce2bd6e4 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Thu, 26 Jan 2023 20:10:04 +0100 Subject: [PATCH 1/2] use UserModel::createFull() instead of constructor --- Controllers/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controllers/UserController.php b/Controllers/UserController.php index aa507e3..2d4933a 100644 --- a/Controllers/UserController.php +++ b/Controllers/UserController.php @@ -81,7 +81,7 @@ final class UserController $S_password_hash = password_hash($S_password, PASSWORD_DEFAULT); - $O_user = new UserModel($S_email, $S_username, $S_password_hash, null, date("Y-m-d"), 0, 0); + $O_user = UserModel::createFull($S_email, $S_username, $S_password_hash, self::currentDate(), self::currentDate(), 0, 0); $O_user->insert(); Session::set_login($O_user->I_ID); From 2f4128beebb5fee25ce58fd4691d888456330032 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Thu, 26 Jan 2023 20:10:11 +0100 Subject: [PATCH 2/2] deal with dates correctly --- Controllers/UserController.php | 7 +++++++ Models/UserModel.php | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Controllers/UserController.php b/Controllers/UserController.php index 2d4933a..53b3c23 100644 --- a/Controllers/UserController.php +++ b/Controllers/UserController.php @@ -7,6 +7,10 @@ ini_set("session.cookie_lifetime", $__SESSION_TIMEOUT); final class UserController { + private static function currentDate(){ + return date("Y-m-d H:i:s"); + } + public function loginAction(Array $A_urlParams = null, Array $A_postParams = null, Array $A_getParams = null) { if (Session::is_login()) { @@ -53,6 +57,9 @@ final class UserController return header("Location: /user/login"); } + $O_user->S_LAST_SEEN = self::currentDate(); + $O_user->update(); + Session::set_login($O_user->I_ID); self::redirectToPreviousPage($A_postParams); diff --git a/Models/UserModel.php b/Models/UserModel.php index 46e04c0..28abcc9 100644 --- a/Models/UserModel.php +++ b/Models/UserModel.php @@ -45,10 +45,11 @@ final class UserModel extends UserSessionModel public function insert(){ $O_model = Model::get(); - $stmt = $O_model->prepare("INSERT INTO USER (EMAIL, USERNAME, PASS_HASH, FIRST_SEEN) VALUES(:email, :username, :password_hash, :first_seen)"); + $stmt = $O_model->prepare("INSERT INTO USER (EMAIL, USERNAME, PASS_HASH, FIRST_SEEN, LAST_SEEN) VALUES(:email, :username, :password_hash, :first_seen, :last_seen)"); $stmt->bindParam("email", $this->S_EMAIL); $stmt->bindParam("username", $this->S_USERNAME); $stmt->bindParam("password_hash", $this->S_PASSWORD_HASH); + $stmt->bindParam("last_seen", $this->S_LAST_SEEN); $stmt->bindParam("first_seen", $this->S_FIRST_SEEN); $stmt->execute(); $this->I_ID = Model::get()->lastInsertId();