-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save user's first login time and output it in occ user:info
#37328
Changes from all commits
badd79d
64b870f
5d64fe0
bf411a4
450cba7
881e272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -560,6 +560,8 @@ protected function prepareUserLogin($firstTimeLogin, $refreshCsrfToken = true) { | |
// read only uses | ||
} | ||
|
||
$userObj = $this->getUser(); | ||
$userObj->updateFirstLoginTimestamp($userObj->getLastLogin()); | ||
// trigger any other initialization | ||
\OC::$server->getEventDispatcher()->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser())); | ||
Comment on lines
+563
to
566
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would feel prettier if the call to updateFirstLoginTimestamp is instead in a Listener for the event firstLogin. |
||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -89,6 +89,9 @@ class User implements IUser { | |||||||
/** @var int|null */ | ||||||||
private $lastLogin; | ||||||||
|
||||||||
/** @var int|null */ | ||||||||
private $firstLogin; | ||||||||
Comment on lines
+92
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please strong type new code |
||||||||
|
||||||||
/** @var \OCP\IConfig */ | ||||||||
private $config; | ||||||||
|
||||||||
|
@@ -243,6 +246,20 @@ public function getLastLogin() { | |||||||
return (int) $this->lastLogin; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* returns the timestamp of the user's first login or 0 if the user did never | ||||||||
* login | ||||||||
* | ||||||||
* @return int | ||||||||
*/ | ||||||||
|
||||||||
public function getFirstLogin() { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be better to return |
||||||||
if ($this->firstLogin === null) { | ||||||||
$this->firstLogin = (int) $this->config->getUserValue($this->uid, 'login', 'firstLogin', 0); | ||||||||
} | ||||||||
return (int) $this->firstLogin; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* updates the timestamp of the most recent login of this user | ||||||||
*/ | ||||||||
|
@@ -260,6 +277,14 @@ public function updateLastLoginTimestamp() { | |||||||
return $firstTimeLogin; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* updates the timestamp of the first login of this user | ||||||||
*/ | ||||||||
public function updateFirstLoginTimestamp(int $timestamp) { | ||||||||
$this->firstLogin = $timestamp; | ||||||||
$this->config->setUserValue($this->uid, 'login', 'firstLogin', (string)$this->firstLogin); | ||||||||
} | ||||||||
Comment on lines
+283
to
+286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be some kind of check about whether a first login timestamp was already set for this user? |
||||||||
|
||||||||
/** | ||||||||
* Delete the user | ||||||||
* | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -270,4 +270,19 @@ public function getQuota(); | |||||
* @since 9.0.0 | ||||||
*/ | ||||||
public function setQuota($quota); | ||||||
|
||||||
/** | ||||||
* returns the timestamp of the user's first login or 0 if the user did never | ||||||
* login | ||||||
* | ||||||
* @return int | ||||||
* @since 27.0.0 | ||||||
*/ | ||||||
public function getFirstLogin(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/** | ||||||
* updates the timestamp of the first login of this user | ||||||
* @since 27.0.0 | ||||||
*/ | ||||||
public function updateFirstLoginTimestamp(int $timestamp); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we only call this from core, does this need to be in the public interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well even in core most of the time the objects will be typed as IUser and not User, most likely this is the case here as well? Especially if it gets moved to a listener, most likely the event will give an IUser instance. |
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creation and first login are not the same thing.
Also, this should handle properly the case where firstlogin is 0.