diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index 61459e40b8b..a90fa0e55ea 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -116,6 +116,7 @@ abstract class AUserData extends OCSController { // Find the data $data['id'] = $targetUserObject->getUID(); + $data['firstLogin'] = $targetUserObject->getFirstLogin() * 1000; $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000; $data['backend'] = $targetUserObject->getBackendClassName(); $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); diff --git a/apps/provisioning_api/lib/ResponseDefinitions.php b/apps/provisioning_api/lib/ResponseDefinitions.php index afa725c110a..2a5d13746cd 100644 --- a/apps/provisioning_api/lib/ResponseDefinitions.php +++ b/apps/provisioning_api/lib/ResponseDefinitions.php @@ -46,6 +46,7 @@ namespace OCA\Provisioning_API; * headlineScope?: Provisioning_APIUserDetailsScope, * id: string, * language: string, + * firstLogin: int, * lastLogin: int, * locale: string, * manager: string, diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index 55298f0164c..de2fd99652c 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -56,6 +56,7 @@ class Info extends Base { 'groups' => $groups, 'quota' => $user->getQuota(), 'storage' => $this->getStorageInfo($user), + 'first_seen' => date(\DateTimeInterface::ATOM, $user->getFirstLogin()), // ISO-8601 'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601 'user_directory' => $user->getHome(), 'backend' => $user->getBackendClassName() diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php index 92a0c735215..9eb5f9afb25 100644 --- a/lib/private/User/LazyUser.php +++ b/lib/private/User/LazyUser.php @@ -60,11 +60,15 @@ class LazyUser implements IUser { return $this->getUser()->setDisplayName($displayName); } - public function getLastLogin() { + public function getLastLogin(): int { return $this->getUser()->getLastLogin(); } - public function updateLastLoginTimestamp() { + public function getFirstLogin(): int { + return $this->getUser()->getFirstLogin(); + } + + public function updateLastLoginTimestamp(): bool { return $this->getUser()->updateLastLoginTimestamp(); } diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 4b1ec4366d0..311f057be54 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -65,8 +65,8 @@ class User implements IUser { /** @var string */ private $home; - /** @var int|null */ - private $lastLogin; + private ?int $lastLogin = null; + private ?int $firstLogin = null; /** @var IAvatarManager */ private $avatarManager; @@ -202,28 +202,42 @@ class User implements IUser { /** * returns the timestamp of the user's last login or 0 if the user did never * login - * - * @return int */ - public function getLastLogin() { + public function getLastLogin(): int { if ($this->lastLogin === null) { $this->lastLogin = (int)$this->config->getUserValue($this->uid, 'login', 'lastLogin', 0); } - return (int)$this->lastLogin; + return $this->lastLogin; + } + + /** + * returns the timestamp of the user's last login or 0 if the user did never + * login + */ + public function getFirstLogin(): int { + if ($this->firstLogin === null) { + $this->firstLogin = (int)$this->config->getUserValue($this->uid, 'login', 'firstLogin', 0); + } + return $this->firstLogin; } /** * updates the timestamp of the most recent login of this user */ - public function updateLastLoginTimestamp() { + public function updateLastLoginTimestamp(): bool { $previousLogin = $this->getLastLogin(); + $firstLogin = $this->getFirstLogin(); $now = time(); - $firstTimeLogin = $previousLogin === 0; + $firstTimeLogin = $firstLogin === 0; if ($now - $previousLogin > 60) { - $this->lastLogin = time(); - $this->config->setUserValue( - $this->uid, 'login', 'lastLogin', (string)$this->lastLogin); + $this->lastLogin = $now; + $this->config->setUserValue($this->uid, 'login', 'lastLogin', (string)$this->lastLogin); + } + + if ($firstTimeLogin) { + $this->firstLogin = $now; + $this->config->setUserValue($this->uid, 'login', 'firstLogin', (string)$this->firstLogin); } return $firstTimeLogin; diff --git a/lib/public/IUser.php b/lib/public/IUser.php index 8c7d6a1283e..f87fd8398e6 100644 --- a/lib/public/IUser.php +++ b/lib/public/IUser.php @@ -50,13 +50,22 @@ interface IUser { * @return int * @since 8.0.0 */ - public function getLastLogin(); + public function getLastLogin(): int; /** - * updates the timestamp of the most recent login of this user + * Returns the timestamp of the user's first login or 0 if the user did never login + * + * @since 31.0.0 + */ + public function getFirstLogin(): int; + + /** + * Updates the timestamp of the most recent login of this user (and first login if needed) + * + * @return bool whether this is the first login * @since 8.0.0 */ - public function updateLastLoginTimestamp(); + public function updateLastLoginTimestamp(): bool; /** * Delete the user