From c99596d12b653b4f4faffaac14d6ddbfe060b867 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Thu, 13 Feb 2014 09:10:24 +0100 Subject: [PATCH] Added last login date to users --- src/Controllers/AuthController.php | 2 ++ src/Models/Entities/UserEntity.php | 1 + src/Models/UserModel.php | 1 + src/Upgrades/mysql/Upgrade10.sql | 1 + src/Upgrades/sqlite/Upgrade10.sql | 1 + src/Views/user-view.phtml | 5 +++++ 6 files changed, 11 insertions(+) create mode 100644 src/Upgrades/mysql/Upgrade10.sql create mode 100644 src/Upgrades/sqlite/Upgrade10.sql diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index ad4fa6b5..39afc7dc 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -104,6 +104,8 @@ class AuthController if (!empty($context->user) and $context->user->id) { $dbUser = UserModel::findById($context->user->id); + $context->user->lastLoginDate = time(); + UserModel::save($context->user); $_SESSION['user'] = serialize($dbUser); } else diff --git a/src/Models/Entities/UserEntity.php b/src/Models/Entities/UserEntity.php index 82666a71..4eb87c02 100644 --- a/src/Models/Entities/UserEntity.php +++ b/src/Models/Entities/UserEntity.php @@ -8,6 +8,7 @@ class UserEntity extends AbstractEntity public $emailUnconfirmed; public $emailConfirmed; public $joinDate; + public $lastLoginDate; public $accessRank; public $settings; public $banned; diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php index a4c3fd9e..a7b064ce 100644 --- a/src/Models/UserModel.php +++ b/src/Models/UserModel.php @@ -34,6 +34,7 @@ class UserModel extends AbstractCrudModel 'email_unconfirmed' => $user->emailUnconfirmed, 'email_confirmed' => $user->emailConfirmed, 'join_date' => $user->joinDate, + 'last_login_date' => $user->lastLoginDate, 'access_rank' => $user->accessRank, 'settings' => $user->settings, 'banned' => $user->banned diff --git a/src/Upgrades/mysql/Upgrade10.sql b/src/Upgrades/mysql/Upgrade10.sql new file mode 100644 index 00000000..c2c3d4d8 --- /dev/null +++ b/src/Upgrades/mysql/Upgrade10.sql @@ -0,0 +1 @@ +ALTER TABLE user ADD COLUMN last_login_date INTEGER DEFAULT NULL; diff --git a/src/Upgrades/sqlite/Upgrade10.sql b/src/Upgrades/sqlite/Upgrade10.sql new file mode 100644 index 00000000..c2c3d4d8 --- /dev/null +++ b/src/Upgrades/sqlite/Upgrade10.sql @@ -0,0 +1 @@ +ALTER TABLE user ADD COLUMN last_login_date INTEGER DEFAULT NULL; diff --git a/src/Views/user-view.phtml b/src/Views/user-view.phtml index 4aa61fc1..dc636d72 100644 --- a/src/Views/user-view.phtml +++ b/src/Views/user-view.phtml @@ -19,6 +19,11 @@ LayoutHelper::addStylesheet('user-view.css'); +
+ Last login: + +
+
Access rank: