mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 06:37:56 -04:00
feat: Add first login timestamp of each user to oc_preferences and user:info output
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
4d15acf4b5
commit
baf7293cfe
6 changed files with 46 additions and 16 deletions
|
|
@ -116,6 +116,7 @@ abstract class AUserDataOCSController 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());
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ namespace OCA\Provisioning_API;
|
|||
* headlineScope?: Provisioning_APIUserDetailsScope,
|
||||
* id: string,
|
||||
* language: string,
|
||||
* firstLogin: int,
|
||||
* lastLogin: int,
|
||||
* locale: string,
|
||||
* manager: string,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue